Skip to content

Commit 9f12414

Browse files
committed
Getting the code prettier for release
1 parent 694013f commit 9f12414

File tree

12 files changed

+118
-159
lines changed

12 files changed

+118
-159
lines changed

AndroidManifest.xml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
android:versionCode="1"
55
android:versionName="1.0">
66

7-
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="17"/>
7+
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17"/>
88
<application
99
android:label="@string/app_name"
1010
android:icon="@drawable/ic_udinic">
11+
12+
<!-- *** Not really needed here, but convenient for copying to other apps that will use this module *** -->
1113
<activity android:name=".authentication.AuthenticatorActivity" android:label="@string/login_label"/>
1214
<activity android:name=".authentication.SignUpActivity" android:label="@string/signup_title" />
1315

@@ -21,7 +23,7 @@
2123

2224
</application>
2325

24-
<!-- Authenticator -->
26+
<!-- *** Not really needed here, but convenient for copying to other apps that will use this module *** -->
2527
<uses-permission android:name="android.permission.INTERNET"/>
2628
<uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS"/>
2729
</manifest>

ExampleApp/AndroidManifest.xml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@
44
android:versionCode="1"
55
android:versionName="1.0">
66

7-
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="17"/>
7+
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17"/>
88
<application
99
android:label="@string/app_name"
10-
android:icon="@drawable/ic_launcher">
10+
android:icon="@drawable/ic_udinic">
1111
<activity android:name=".Main1">
1212
<intent-filter>
1313
<category android:name="android.intent.category.LAUNCHER"/>
1414
<action android:name="android.intent.action.MAIN"/>
1515
</intent-filter>
1616
</activity>
1717

18-
<!-- Authenticator shit needs to be declared here in order for the app to recognize it-->
18+
<!-- Authenticator related activities and service needs to be declared here in order for the app to recognize them-->
1919
<activity android:name="com.udinic.accounts_authenticator_example.authentication.AuthenticatorActivity" android:label="@string/login_label"/>
2020
<activity android:name="com.udinic.accounts_authenticator_example.authentication.SignUpActivity" android:label="@string/signup_title"/>
2121
<service android:name="com.udinic.accounts_authenticator_example.authentication.UdinicAuthenticatorService">
@@ -37,8 +37,4 @@
3737
<uses-permission android:name="android.permission.INTERNET"/>
3838
<uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS"/>
3939

40-
<permission-group android:name="com.udinic.permission_group" android:label="@string/perm_group_name"/>
41-
<permission android:name="com.udinic.permission" android:permissionGroup="com.udinic.permission_group" android:description="@string/per_desc" android:label="@string/per_label" android:protectionLevel="dangerous"/>
42-
<!--<uses-permission android:name="com.udinic.permission"/>-->
43-
4440
</manifest>

ExampleApp/res/values/strings.xml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<resources>
3-
<string name="app_name">ExampleApp</string>
4-
<string name="per_desc">Udini is the man</string>
5-
<string name="per_label">udini per</string>
6-
<string name="perm_group_name">Udinic Perms</string>
3+
<string name="app_name">Authenticator sample app</string>
74
</resources>

ExampleApp/src/com/udinic/accounts_example/Main1.java

Lines changed: 34 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
public class Main1 extends Activity {
2525

2626
private String TAG = this.getClass().getSimpleName();
27-
private android.os.Handler mHandler = new android.os.Handler();
2827
private AccountManager mAccountManager;
2928

3029
@Override
@@ -57,7 +56,6 @@ public void onClick(View v) {
5756
findViewById(R.id.btnInvalidateAuthToken).setOnClickListener(new View.OnClickListener() {
5857
@Override
5958
public void onClick(View v) {
60-
Log.d(TAG, "Dsds");
6159
showAccountPicker(AUTHTOKEN_TYPE_FULL_ACCESS, true);
6260
}
6361
});
@@ -75,22 +73,12 @@ private void addNewAccount(String accountType, String authTokenType) {
7573
public void run(AccountManagerFuture<Bundle> future) {
7674
try {
7775
Bundle bnd = future.getResult();
78-
runOnUiThread(new Runnable() {
79-
@Override
80-
public void run() {
81-
//To change body of implemented methods use File | Settings | File Templates.
82-
Toast.makeText(getBaseContext(), "Account was created", Toast.LENGTH_SHORT).show();
83-
}
84-
});
85-
86-
Log.d("udini", "AddNewAccount Bundle is " + bnd);
76+
showMessage("Account was created");
77+
Log.d("udinic", "AddNewAccount Bundle is " + bnd);
8778

88-
} catch (OperationCanceledException e) {
89-
e.printStackTrace();
90-
} catch (IOException e) {
91-
e.printStackTrace();
92-
} catch (AuthenticatorException e) {
79+
} catch (Exception e) {
9380
e.printStackTrace();
81+
showMessage(e.getMessage());
9482
}
9583
}
9684
}, null);
@@ -131,7 +119,7 @@ public void onClick(DialogInterface dialog, int which) {
131119
* @param authTokenType
132120
*/
133121
private void getExistingAccountAuthToken(Account account, String authTokenType) {
134-
final AccountManagerFuture<Bundle> future = mAccountManager.getAuthToken(account, authTokenType, null, this, null,null);
122+
final AccountManagerFuture<Bundle> future = mAccountManager.getAuthToken(account, authTokenType, null, this, null, null);
135123

136124
new Thread(new Runnable() {
137125
@Override
@@ -140,26 +128,21 @@ public void run() {
140128
Bundle bnd = future.getResult();
141129

142130
final String authtoken = bnd.getString(AccountManager.KEY_AUTHTOKEN);
143-
runOnUiThread(new Runnable() {
144-
@Override
145-
public void run() {
146-
//To change body of implemented methods use File | Settings | File Templates.
147-
Toast.makeText(getBaseContext(), ((authtoken != null) ? "SUCCESS!" : "FAIL"), Toast.LENGTH_SHORT).show();
148-
}
149-
});
150-
Log.d("udini", "GetToken Bundle is " + bnd);
151-
} catch (OperationCanceledException e) {
152-
e.printStackTrace();
153-
} catch (IOException e) {
154-
e.printStackTrace();
155-
} catch (AuthenticatorException e) {
131+
showMessage((authtoken != null) ? "SUCCESS!\ntoken: " + authtoken : "FAIL");
132+
Log.d("udinic", "GetToken Bundle is " + bnd);
133+
} catch (Exception e) {
156134
e.printStackTrace();
135+
showMessage(e.getMessage());
157136
}
158-
159137
}
160138
}).start();
161139
}
162140

141+
/**
142+
* Invalidates the auth token for the account
143+
* @param account
144+
* @param authTokenType
145+
*/
163146
private void invalidateAuthToken(final Account account, String authTokenType) {
164147
final AccountManagerFuture<Bundle> future = mAccountManager.getAuthToken(account, authTokenType, null, this, null,null);
165148

@@ -171,21 +154,11 @@ public void run() {
171154

172155
final String authtoken = bnd.getString(AccountManager.KEY_AUTHTOKEN);
173156
mAccountManager.invalidateAuthToken(account.type, authtoken);
174-
runOnUiThread(new Runnable() {
175-
@Override
176-
public void run() {
177-
Toast.makeText(getBaseContext(), account.name + " invalidated", Toast.LENGTH_SHORT).show();
178-
}
179-
});
180-
Log.d("udini", "GetToken Bundle is " + bnd);
181-
} catch (OperationCanceledException e) {
182-
e.printStackTrace();
183-
} catch (IOException e) {
184-
e.printStackTrace();
185-
} catch (AuthenticatorException e) {
157+
showMessage(account.name + " invalidated");
158+
} catch (Exception e) {
186159
e.printStackTrace();
160+
showMessage(e.getMessage());
187161
}
188-
189162
}
190163
}).start();
191164
}
@@ -207,24 +180,27 @@ public void run(AccountManagerFuture<Bundle> future) {
207180
try {
208181
bnd = future.getResult();
209182
final String authtoken = bnd.getString(AccountManager.KEY_AUTHTOKEN);
210-
runOnUiThread(new Runnable() {
211-
@Override
212-
public void run() {
213-
//To change body of implemented methods use File | Settings | File Templates.
214-
Toast.makeText(getBaseContext(), ((authtoken != null) ? "SUCCESS!" : "FAIL"), Toast.LENGTH_SHORT).show();
215-
}
216-
});
217-
Log.d("udini", "GetTokenForAccount Bundle is " + bnd);
218-
219-
} catch (OperationCanceledException e) {
220-
e.printStackTrace();
221-
} catch (IOException e) {
222-
e.printStackTrace();
223-
} catch (AuthenticatorException e) {
183+
showMessage(((authtoken != null) ? "SUCCESS!\ntoken: " + authtoken : "FAIL"));
184+
Log.d("udinic", "GetTokenForAccount Bundle is " + bnd);
185+
186+
} catch (Exception e) {
224187
e.printStackTrace();
188+
showMessage(e.getMessage());
225189
}
226190
}
227191
}
228192
, null);
229193
}
194+
195+
private void showMessage(final String msg) {
196+
if (msg == null || msg.trim().equals(""))
197+
return;
198+
199+
runOnUiThread(new Runnable() {
200+
@Override
201+
public void run() {
202+
Toast.makeText(getBaseContext(), msg, Toast.LENGTH_SHORT).show();
203+
}
204+
});
205+
}
230206
}

ExampleApp2/AndroidManifest.xml

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@
44
android:versionCode="1"
55
android:versionName="1.0">
66

7-
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="17"/>
7+
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17"/>
88
<application
99
android:label="@string/app_name"
10-
android:icon="@drawable/ic_launcher">
10+
android:icon="@drawable/ic_udinic">
1111
<activity android:name=".Main2">
1212
<intent-filter>
1313
<category android:name="android.intent.category.LAUNCHER"/>
1414
<action android:name="android.intent.action.MAIN"/>
1515
</intent-filter>
1616
</activity>
1717

18-
<!-- Authenticator shit -->
19-
<activity android:name="com.udinic.accounts_authenticator_example.authentication.AuthenticatorActivity" android:label="@string/login_label" android:exported="true"/>
20-
<activity android:name="com.udinic.accounts_authenticator_example.authentication.SignUpActivity" android:label="@string/signup_title" android:exported="true"/>
18+
<!-- Authenticator related activities and service needs to be declared here in order for the app to recognize them-->
19+
<activity android:name="com.udinic.accounts_authenticator_example.authentication.AuthenticatorActivity" android:label="@string/login_label"/>
20+
<activity android:name="com.udinic.accounts_authenticator_example.authentication.SignUpActivity" android:label="@string/signup_title"/>
2121
<service android:name="com.udinic.accounts_authenticator_example.authentication.UdinicAuthenticatorService">
2222
<intent-filter>
2323
<action android:name="android.accounts.AccountAuthenticator" />
@@ -32,12 +32,9 @@
3232
<uses-permission android:name="android.permission.USE_CREDENTIALS"/>
3333
<uses-permission android:name="android.permission.GET_ACCOUNTS"/>
3434
<uses-permission android:name="android.permission.MANAGE_ACCOUNTS"/>
35-
<!--<uses-permission android:name="com.udinic.permission"/>-->
3635

3736
<!-- Authenticator -->
3837
<uses-permission android:name="android.permission.INTERNET"/>
3938
<uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS"/>
40-
<!--<permission android:name="com.udinic.permission"/>-->
41-
<!--<uses-permission android:name="com.udinic.permission"/>-->
4239

4340
</manifest>

ExampleApp2/res/layout/main.xml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,24 @@
1010
android:layout_width="match_parent"
1111
android:layout_height="wrap_content"
1212
android:padding="10dp"
13-
android:text="Add Account"/>
13+
android:text="addAccount"/>
1414

1515
<Button android:id="@+id/btnGetAuthToken"
1616
android:layout_width="match_parent"
1717
android:layout_height="wrap_content"
1818
android:padding="10dp"
19-
android:text="Get Auth token"/>
19+
android:text="getAuthToken"/>
2020

2121
<Button android:id="@+id/btnGetAuthTokenConvenient"
2222
android:layout_width="match_parent"
2323
android:layout_height="wrap_content"
2424
android:padding="10dp"
25-
android:text="Get Auth Token convenient"/>
25+
android:text="getAuthTokenByFeatures"/>
2626

2727
<Button android:id="@+id/btnInvalidateAuthToken"
2828
android:layout_width="match_parent"
2929
android:layout_height="wrap_content"
3030
android:padding="10dp"
31-
android:text="InvalidateAuthToken"/>
32-
31+
android:text="invalidateAuthToken"/>
3332

3433
</LinearLayout>

ExampleApp2/res/values/strings.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<resources>
3-
<string name="app_name">ExampleApp2</string>
3+
<string name="app_name">Authenticator sample app 2</string>
44
</resources>

0 commit comments

Comments
 (0)