Moved version to last item of preferences.
Cleaned code in various places.
This commit is contained in:
parent
ae680d0e40
commit
cc7b7ce8ea
8 changed files with 115 additions and 74 deletions
4
.idea/inspectionProfiles/Project_Default.xml
generated
4
.idea/inspectionProfiles/Project_Default.xml
generated
|
@ -33,5 +33,9 @@
|
|||
<option name="IGNORE_POINT_TO_ITSELF" value="false" />
|
||||
<option name="myAdditionalJavadocTags" value="created" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="LoggerInitializedWithForeignClass" enabled="false" level="WARNING" enabled_by_default="false">
|
||||
<option name="loggerClassName" value="org.apache.log4j.Logger,org.slf4j.LoggerFactory,org.apache.commons.logging.LogFactory,java.util.logging.Logger" />
|
||||
<option name="loggerFactoryMethodName" value="getLogger,getLogger,getLog,getLogger" />
|
||||
</inspection_tool>
|
||||
</profile>
|
||||
</component>
|
24
.idea/misc.xml
generated
24
.idea/misc.xml
generated
|
@ -3,6 +3,30 @@
|
|||
<component name="EntryPointsManager">
|
||||
<entry_points version="2.0" />
|
||||
</component>
|
||||
<component name="NullableNotNullManager">
|
||||
<option name="myDefaultNullable" value="org.jetbrains.annotations.Nullable" />
|
||||
<option name="myDefaultNotNull" value="android.support.annotation.NonNull" />
|
||||
<option name="myNullables">
|
||||
<value>
|
||||
<list size="4">
|
||||
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.Nullable" />
|
||||
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nullable" />
|
||||
<item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.Nullable" />
|
||||
<item index="3" class="java.lang.String" itemvalue="android.support.annotation.Nullable" />
|
||||
</list>
|
||||
</value>
|
||||
</option>
|
||||
<option name="myNotNulls">
|
||||
<value>
|
||||
<list size="4">
|
||||
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.NotNull" />
|
||||
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nonnull" />
|
||||
<item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.NonNull" />
|
||||
<item index="3" class="java.lang.String" itemvalue="android.support.annotation.NonNull" />
|
||||
</list>
|
||||
</value>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectLevelVcsManager" settingsEditedManually="false">
|
||||
<OptionsSetting value="true" id="Add" />
|
||||
<OptionsSetting value="true" id="Remove" />
|
||||
|
|
|
@ -89,6 +89,7 @@
|
|||
<orderEntry type="library" exported="" name="gson-2.1" level="project" />
|
||||
<orderEntry type="library" exported="" name="protobuf-java-2.2.0" level="project" />
|
||||
<orderEntry type="library" exported="" name="google-http-client-1.7.0-beta" level="project" />
|
||||
<orderEntry type="library" exported="" name="support-annotations-20.0.0" level="project" />
|
||||
<orderEntry type="library" exported="" name="google-api-client-1.7.0-beta" level="project" />
|
||||
<orderEntry type="library" exported="" name="bitlyj-2.0.0" level="project" />
|
||||
<orderEntry type="library" exported="" name="google-http-client-android2-1.7.0-beta" level="project" />
|
||||
|
|
|
@ -9,7 +9,7 @@ android {
|
|||
minSdkVersion 14
|
||||
targetSdkVersion 22
|
||||
versionCode 2
|
||||
versionName "1.1b9"
|
||||
versionName "1.1b10"
|
||||
}
|
||||
buildTypes {
|
||||
release {
|
||||
|
@ -28,4 +28,5 @@ android {
|
|||
dependencies {
|
||||
compile fileTree(dir: 'libs', include: ['*.jar'])
|
||||
//compile 'com.android.support:appcompat-v7:22.0.0'
|
||||
compile 'com.android.support:support-annotations:20.0.0'
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
*/
|
||||
package net.thauvin.erik.android.emaily;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
|
@ -43,63 +44,65 @@ import android.util.AttributeSet;
|
|||
import android.view.View;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
/**
|
||||
* The <code>BitlyCredsDialog</code> class implements a bit.ly credential dialog.
|
||||
*
|
||||
*
|
||||
* @author <a href="mailto:erik@thauvin.net">Erik C. Thauvin</a>
|
||||
* @created March 28, 2012
|
||||
* @since 1.0
|
||||
*/
|
||||
public class BitlyCredsDialog extends DialogPreference
|
||||
{
|
||||
private final Context mContext;
|
||||
private EditText username;
|
||||
private EditText apikey;
|
||||
private final Context context;
|
||||
private EditText username;
|
||||
private EditText apikey;
|
||||
|
||||
public BitlyCredsDialog(Context context, AttributeSet attrs)
|
||||
{
|
||||
super(context, attrs);
|
||||
mContext = context;
|
||||
setPersistent(false);
|
||||
}
|
||||
public BitlyCredsDialog(Context context, AttributeSet attrs)
|
||||
{
|
||||
super(context, attrs);
|
||||
this.context = context;
|
||||
setPersistent(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onBindDialogView(View view)
|
||||
{
|
||||
super.onBindDialogView(view);
|
||||
@Override
|
||||
protected void onBindDialogView(@NonNull View view)
|
||||
{
|
||||
super.onBindDialogView(view);
|
||||
|
||||
final SharedPreferences sharedPrefs = getSharedPreferences();
|
||||
username = (EditText) view.findViewById(R.id.bitly_username_edit);
|
||||
apikey = (EditText) view.findViewById(R.id.bitly_apikey_edit);
|
||||
final TextView textFld = (TextView) view.findViewById(R.id.bitly_text_fld);
|
||||
final SharedPreferences sharedPrefs = getSharedPreferences();
|
||||
username = (EditText) view.findViewById(R.id.bitly_username_edit);
|
||||
apikey = (EditText) view.findViewById(R.id.bitly_apikey_edit);
|
||||
final TextView textFld = (TextView) view.findViewById(R.id.bitly_text_fld);
|
||||
|
||||
username.setText(sharedPrefs.getString(mContext.getString(R.string.prefs_key_bitly_username), ""));
|
||||
apikey.setText(sharedPrefs.getString(mContext.getString(R.string.prefs_key_bitly_apikey), ""));
|
||||
username.setText(sharedPrefs.getString(context.getString(R.string.prefs_key_bitly_username), ""));
|
||||
apikey.setText(sharedPrefs.getString(context.getString(R.string.prefs_key_bitly_apikey), ""));
|
||||
|
||||
textFld.setOnClickListener(new View.OnClickListener()
|
||||
{
|
||||
public void onClick(View v)
|
||||
{
|
||||
final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(mContext.getString(R.string.prefs_bitly_creds_url)));
|
||||
mContext.startActivity(intent);
|
||||
}
|
||||
});
|
||||
}
|
||||
textFld.setOnClickListener(new View.OnClickListener()
|
||||
{
|
||||
public void onClick(View v)
|
||||
{
|
||||
final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(context.getString(R.string.prefs_bitly_creds_url)));
|
||||
context.startActivity(intent);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDialogClosed(boolean positiveResult)
|
||||
{
|
||||
super.onDialogClosed(positiveResult);
|
||||
@SuppressLint("CommitPrefEdits")
|
||||
@Override
|
||||
protected void onDialogClosed(boolean positiveResult)
|
||||
{
|
||||
super.onDialogClosed(positiveResult);
|
||||
|
||||
if (positiveResult)
|
||||
{
|
||||
final SharedPreferences sharedPrefs = getSharedPreferences();
|
||||
final Editor editor = sharedPrefs.edit();
|
||||
editor.putString(mContext.getString(R.string.prefs_key_bitly_username), username.getText().toString());
|
||||
editor.putString(mContext.getString(R.string.prefs_key_bitly_apikey), apikey.getText().toString());
|
||||
editor.commit();
|
||||
}
|
||||
if (positiveResult)
|
||||
{
|
||||
final SharedPreferences sharedPrefs = getSharedPreferences();
|
||||
final Editor editor = sharedPrefs.edit();
|
||||
editor.putString(context.getString(R.string.prefs_key_bitly_username), username.getText().toString());
|
||||
editor.putString(context.getString(R.string.prefs_key_bitly_apikey), apikey.getText().toString());
|
||||
editor.commit();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,6 +47,7 @@ import android.accounts.AccountManager;
|
|||
import android.accounts.AccountManagerCallback;
|
||||
import android.accounts.AccountManagerFuture;
|
||||
import android.accounts.OperationCanceledException;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.ProgressDialog;
|
||||
|
@ -84,7 +85,6 @@ import com.google.api.services.urlshortener.model.Url;
|
|||
* @created Oct 11, 2011
|
||||
* @since 1.0
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public class Emaily extends Activity
|
||||
{
|
||||
private static final String ACCOUNT_TYPE = "com.google";
|
||||
|
@ -93,6 +93,7 @@ public class Emaily extends Activity
|
|||
private String appName;
|
||||
private SharedPreferences sharedPrefs;
|
||||
|
||||
@SuppressLint("CommitPrefEdits")
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
|
@ -158,12 +159,14 @@ public class Emaily extends Activity
|
|||
}
|
||||
else
|
||||
{
|
||||
//noinspection ConstantConditions
|
||||
startEmailyTask(intent, isGoogl, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//noinspection ConstantConditions
|
||||
startEmailyTask(intent, isGoogl, false);
|
||||
}
|
||||
}
|
||||
|
@ -187,11 +190,13 @@ public class Emaily extends Activity
|
|||
|
||||
if (isGoogl)
|
||||
{
|
||||
//noinspection ConstantConditions
|
||||
task = new EmailyTask(getPref(R.string.prefs_key_googl_account), getPref(R.string.prefs_key_googl_token), isGoogl,
|
||||
getBoolPref(R.string.prefs_key_html_chkbox), isRetry);
|
||||
}
|
||||
else
|
||||
{
|
||||
//noinspection ConstantConditions
|
||||
task = new EmailyTask(getPref(R.string.prefs_key_bitly_username), getPref(R.string.prefs_key_bitly_apikey), isGoogl,
|
||||
getBoolPref(R.string.prefs_key_html_chkbox), isRetry);
|
||||
}
|
||||
|
@ -229,6 +234,7 @@ public class Emaily extends Activity
|
|||
|
||||
googleAccountManager.manager.getAuthToken(account, OAUTH_URL, null, Emaily.this, new AccountManagerCallback<Bundle>()
|
||||
{
|
||||
@SuppressLint("CommitPrefEdits")
|
||||
@Override
|
||||
public void run(AccountManagerFuture<Bundle> future)
|
||||
{
|
||||
|
@ -276,7 +282,8 @@ public class Emaily extends Activity
|
|||
*
|
||||
* @param intent The original intent.
|
||||
*/
|
||||
public void retry(final Intent intent)
|
||||
@SuppressLint("CommitPrefEdits")
|
||||
private void retry(final Intent intent)
|
||||
{
|
||||
sharedPrefs.edit().putLong(getString(R.string.prefs_key_googl_token_expiry), 0L).commit();
|
||||
|
||||
|
@ -300,7 +307,7 @@ public class Emaily extends Activity
|
|||
* @param id The string id.
|
||||
* @return The preference value.
|
||||
*/
|
||||
public String getPref(int id)
|
||||
private String getPref(int id)
|
||||
{
|
||||
return getPref(id, "");
|
||||
}
|
||||
|
@ -312,7 +319,7 @@ public class Emaily extends Activity
|
|||
* @param defaultValue The default value, used if the preference is empty.
|
||||
* @return The preference value.
|
||||
*/
|
||||
public String getPref(int id, String defaultValue)
|
||||
private String getPref(int id, String defaultValue)
|
||||
{
|
||||
return sharedPrefs.getString(getString(id), defaultValue);
|
||||
}
|
||||
|
@ -323,7 +330,7 @@ public class Emaily extends Activity
|
|||
* @param id The string id.
|
||||
* @return The preference value.
|
||||
*/
|
||||
public boolean getBoolPref(int id)
|
||||
private boolean getBoolPref(int id)
|
||||
{
|
||||
return getBoolPref(id, false);
|
||||
}
|
||||
|
@ -335,7 +342,7 @@ public class Emaily extends Activity
|
|||
* @param defaultValue The default value, used if the preference is empty.
|
||||
* @return The preference value.
|
||||
*/
|
||||
public boolean getBoolPref(int id, boolean defaultValue)
|
||||
private boolean getBoolPref(int id, boolean defaultValue)
|
||||
{
|
||||
return sharedPrefs.getBoolean(getString(id), defaultValue);
|
||||
}
|
||||
|
@ -572,6 +579,7 @@ public class Emaily extends Activity
|
|||
{
|
||||
if (!result.hasError() && shortUrl.length() > 0)
|
||||
{
|
||||
@SuppressWarnings("deprecation")
|
||||
final ClipboardManager clip = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
clip.setText(shortUrl);
|
||||
|
||||
|
|
|
@ -35,6 +35,7 @@ package net.thauvin.erik.android.emaily;
|
|||
|
||||
import java.util.Locale;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.SharedPreferences.Editor;
|
||||
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
|
||||
|
@ -58,10 +59,9 @@ import android.preference.PreferenceScreen;
|
|||
public class EmailyPrefs extends PreferenceActivity implements OnSharedPreferenceChangeListener
|
||||
{
|
||||
private SharedPreferences sharedPrefs;
|
||||
private Editor prefsEditor;
|
||||
|
||||
private CheckBoxPreference mGooglBox;
|
||||
private BitlyCredsDialog mBitlyCreds;
|
||||
private CheckBoxPreference googlBox;
|
||||
private BitlyCredsDialog bitlyCreds;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState)
|
||||
|
@ -71,17 +71,16 @@ public class EmailyPrefs extends PreferenceActivity implements OnSharedPreferenc
|
|||
addPreferencesFromResource(R.xml.prefs);
|
||||
|
||||
sharedPrefs = getPreferenceScreen().getSharedPreferences();
|
||||
prefsEditor = sharedPrefs.edit();
|
||||
|
||||
mGooglBox = (CheckBoxPreference) findPreference(getString(R.string.prefs_key_googl_chkbox));
|
||||
mBitlyCreds = (BitlyCredsDialog) findPreference(getString(R.string.prefs_key_bitly_creds));
|
||||
googlBox = (CheckBoxPreference) findPreference(getString(R.string.prefs_key_googl_chkbox));
|
||||
bitlyCreds = (BitlyCredsDialog) findPreference(getString(R.string.prefs_key_bitly_creds));
|
||||
|
||||
setSummary(mBitlyCreds, getString(R.string.prefs_key_bitly_username), getString(R.string.prefs_bitly_creds_summary));
|
||||
setSummary(mGooglBox, getString(R.string.prefs_key_googl_account), "");
|
||||
setSummary(bitlyCreds, getString(R.string.prefs_key_bitly_username), getString(R.string.prefs_bitly_creds_summary));
|
||||
setSummary(googlBox, getString(R.string.prefs_key_googl_account), "");
|
||||
|
||||
if (mGooglBox.isChecked())
|
||||
if (googlBox.isChecked())
|
||||
{
|
||||
mBitlyCreds.setEnabled(false);
|
||||
bitlyCreds.setEnabled(false);
|
||||
}
|
||||
|
||||
final Preference version = findPreference(getString(R.string.prefs_key_version));
|
||||
|
@ -120,29 +119,31 @@ public class EmailyPrefs extends PreferenceActivity implements OnSharedPreferenc
|
|||
sharedPrefs.unregisterOnSharedPreferenceChangeListener(this);
|
||||
}
|
||||
|
||||
@SuppressLint("CommitPrefEdits")
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key)
|
||||
{
|
||||
if (key.equals(getString(R.string.prefs_key_bitly_username)))
|
||||
{
|
||||
setSummary(mBitlyCreds, key, getString(R.string.prefs_bitly_creds_summary));
|
||||
setSummary(bitlyCreds, key, getString(R.string.prefs_bitly_creds_summary));
|
||||
}
|
||||
else if (key.equals(getString(R.string.prefs_key_googl_chkbox)))
|
||||
{
|
||||
final boolean checked = mGooglBox.isChecked();
|
||||
final boolean checked = googlBox.isChecked();
|
||||
|
||||
mBitlyCreds.setEnabled(!checked);
|
||||
bitlyCreds.setEnabled(!checked);
|
||||
|
||||
prefsEditor.putBoolean(getString(R.string.prefs_key_googl_enabled), checked);
|
||||
final Editor editor = sharedPrefs.edit();
|
||||
editor.putBoolean(getString(R.string.prefs_key_googl_enabled), checked);
|
||||
|
||||
if (!checked)
|
||||
{
|
||||
prefsEditor.putString(getString(R.string.prefs_key_googl_account), "");
|
||||
prefsEditor.putLong(getString(R.string.prefs_key_googl_token_expiry), 0L);
|
||||
mGooglBox.setSummary("");
|
||||
editor.putString(getString(R.string.prefs_key_googl_account), "");
|
||||
editor.putLong(getString(R.string.prefs_key_googl_token_expiry), 0L);
|
||||
googlBox.setSummary("");
|
||||
}
|
||||
|
||||
prefsEditor.commit();
|
||||
editor.commit();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -25,13 +25,6 @@
|
|||
android:title="@string/prefs_html_chkbox_title"/>
|
||||
</PreferenceCategory>
|
||||
<PreferenceCategory android:title="@string/prefs_about_title">
|
||||
<Preference
|
||||
android:enabled="false"
|
||||
android:key="@string/prefs_key_version"
|
||||
android:singleLine="true"
|
||||
android:summary="@string/prefs_copyright"
|
||||
android:title="@string/prefs_version_title"/>
|
||||
|
||||
<PreferenceScreen
|
||||
android:summary="@string/prefs_help_summary"
|
||||
android:title="@string/prefs_help_title">
|
||||
|
@ -47,6 +40,12 @@
|
|||
android:action="android.intent.action.VIEW"
|
||||
android:data="@string/prefs_feedback_url"/>
|
||||
</PreferenceScreen>
|
||||
<Preference
|
||||
android:enabled="false"
|
||||
android:key="@string/prefs_key_version"
|
||||
android:singleLine="true"
|
||||
android:summary="@string/prefs_copyright"
|
||||
android:title="@string/prefs_version_title"/>
|
||||
</PreferenceCategory>
|
||||
|
||||
</PreferenceScreen>
|
Loading…
Add table
Add a link
Reference in a new issue