Android Open Source - anti-piracy-android-app Preferences Activity






From Project

Back to project page anti-piracy-android-app.

License

The source code is released under:

Apache License

If you think the Android project anti-piracy-android-app listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package mil.nga.giat.asam;
/*from   ww w . j a  va  2s .  co  m*/
import java.lang.ref.WeakReference;
import java.util.List;

import mil.nga.giat.asam.db.AsamDbHelper;
import mil.nga.giat.asam.model.AsamBean;
import mil.nga.giat.asam.model.AsamJsonParser;
import mil.nga.giat.asam.net.AsamWebService;
import mil.nga.giat.asam.util.AsamConstants;
import mil.nga.giat.asam.util.AsamLog;
import mil.nga.giat.asam.util.AsamUtils;
import mil.nga.giat.asam.util.SyncTime;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.preference.PreferenceManager;
import android.support.v7.app.ActionBarActivity;
import android.view.MenuItem;
import android.view.View;
import android.widget.CheckBox;
import android.widget.TextView;

public class PreferencesActivity extends ActionBarActivity {

    private static class QueryHandler extends Handler {
        
        WeakReference<PreferencesActivity> mPreferencesActivity;

        QueryHandler(PreferencesActivity preferencesActivity) {
            mPreferencesActivity = new WeakReference<PreferencesActivity>(preferencesActivity);
        }

        @Override
        public void handleMessage(Message message) {
            PreferencesActivity preferencesActivity = mPreferencesActivity.get();
            preferencesActivity.mQueryProgressDialog.dismiss();
            if (preferencesActivity.mQueryError) {
                preferencesActivity.mQueryError = false;
                preferencesActivity.showSimpleDialog(preferencesActivity.getString(R.string.preferences_query_error_text), preferencesActivity.getString(R.string.preferences_query_error_text));
                return;
            }
            SyncTime.finishedSync(preferencesActivity);
            TextView lastSyncTimeUI = (TextView)preferencesActivity.findViewById(R.id.preferences_last_sync_time_ui);
            lastSyncTimeUI.setText(SyncTime.getLastSyncTimeAsText(preferencesActivity));
            preferencesActivity.showSimpleDialog(preferencesActivity.getString(R.string.preferences_sync_complete_title_text), preferencesActivity.getString(R.string.preferences_sync_complete_description_text));
        }
    }
    
    private CheckBox mDisclaimerCheckBoxUI;
    private volatile boolean mQueryError;
    private QueryHandler mQueryHandler;
    private ProgressDialog mQueryProgressDialog;
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        AsamLog.i(PreferencesActivity.class.getName() + ":onCreate");
        setContentView(R.layout.preferences);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
        mDisclaimerCheckBoxUI = (CheckBox)findViewById(R.id.preferences_hide_disclaimer_checkbox_ui);
        mDisclaimerCheckBoxUI.setChecked(preferences.getBoolean(AsamConstants.HIDE_DISCLAIMER_KEY, false));
        
        // Called to handle the UI after the query has run.
        mQueryHandler = new QueryHandler(this);
    }
    
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {        
        int itemId = item.getItemId();
        if (itemId == android.R.id.home) {
            finish();
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
    
    public void syncButtonClicked(View view) {
        if (SyncTime.isSynched(this)) {
            showSimpleDialog(getString(R.string.preferences_no_sync_title_text), getString(R.string.preferences_no_sync_description_text));
            return;
        }
        mQueryProgressDialog = ProgressDialog.show(this, getString(R.string.preferences_query_progress_dialog_title_text), getString(R.string.preferences_query_progress_dialog_content_text), true);
        new QueryThread().start();
    }
    
    public void disclaimerButtonClicked(View view) {
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
        SharedPreferences.Editor editor = preferences.edit();
        editor.putBoolean(AsamConstants.HIDE_DISCLAIMER_KEY, mDisclaimerCheckBoxUI.isChecked());
        editor.commit();
    }
    
    @Override
    protected void onResume() {
        super.onResume();
        AsamLog.i(PreferencesActivity.class.getName() + ":onResume");
        TextView lastSyncTimeUI = (TextView)findViewById(R.id.preferences_last_sync_time_ui);
        lastSyncTimeUI.setText(SyncTime.getLastSyncTimeAsText(this));
    }
    
    private void showSimpleDialog(String title, String message) {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle(title);
        builder.setMessage(message);
        builder.setPositiveButton(getString(R.string.preferences_ok_button_text), new DialogInterface.OnClickListener() {
            
            @Override
            public void onClick(DialogInterface dialog, int id) {
                dialog.cancel();
            }
        });
        builder.show();
    }
    
    private class QueryThread extends Thread {
        
        @Override
        public void run() {
            mQueryError = false;
            Context context = PreferencesActivity.this;
            String json = null;
            SQLiteDatabase db = null;
            try {
                AsamWebService webService = new AsamWebService(context);
                json = webService.query();
                if (!AsamUtils.isEmpty(json)) {
                    AsamJsonParser parser = new AsamJsonParser();
                    List<AsamBean> asams = parser.parseJson(json);
                    if (asams.size() > 0) {
                        
                        // Do a diff of what the web service returned and what's currently in the db.
                        AsamDbHelper dbHelper = new AsamDbHelper(context);
                        db = dbHelper.getWritableDatabase();
                        asams = dbHelper.removeDuplicates(db, asams);
                        dbHelper.insertAsams(db, asams);
                    }
                }
                SyncTime.finishedSync(context);
            }
            catch (Exception caught) {
                AsamLog.e("There was an error parsing ASAM feed", caught);
                mQueryError = true;
            }
            finally {
                if (db != null) {
                    db.close();
                    db = null;
                }
            }
            mQueryHandler.sendEmptyMessage(0);
        }
    }
}




Java Source Code List

mil.nga.giat.asam.AsamListActivity.java
mil.nga.giat.asam.AsamListFragment.java
mil.nga.giat.asam.AsamListReportTabletActivity.java
mil.nga.giat.asam.AsamReportActivity.java
mil.nga.giat.asam.AsamReportFragment.java
mil.nga.giat.asam.Asam.java
mil.nga.giat.asam.DisclaimerActivity.java
mil.nga.giat.asam.DisclaimerDialogFragment.java
mil.nga.giat.asam.InfoActivity.java
mil.nga.giat.asam.InfoDialogFragment.java
mil.nga.giat.asam.InfoFragment.java
mil.nga.giat.asam.LaunchScreenActivity.java
mil.nga.giat.asam.LegalActivity.java
mil.nga.giat.asam.LegalDetailsActivity.java
mil.nga.giat.asam.LegalDetailsFragment.java
mil.nga.giat.asam.LegalFragment.java
mil.nga.giat.asam.LegalTabletActivity.java
mil.nga.giat.asam.MainActivity.java
mil.nga.giat.asam.PreferencesActivity.java
mil.nga.giat.asam.PreferencesDialogFragment.java
mil.nga.giat.asam.SortAsamListDialogFragment.java
mil.nga.giat.asam.TextQueryActivity.java
mil.nga.giat.asam.TextQueryDialogFragment.java
mil.nga.giat.asam.connectivity.NetworkChangeReceiver.java
mil.nga.giat.asam.connectivity.OfflineBannerFragment.java
mil.nga.giat.asam.db.AsamDbHelper.java
mil.nga.giat.asam.jackson.deserializer.Deserializer.java
mil.nga.giat.asam.jackson.deserializer.FeatureDeserializer.java
mil.nga.giat.asam.jackson.deserializer.GeometryDeserializer.java
mil.nga.giat.asam.map.AllAsamsMapActivity.java
mil.nga.giat.asam.map.AllAsamsMapTabletActivity.java
mil.nga.giat.asam.map.BackgroundTileProvider.java
mil.nga.giat.asam.map.OfflineMap.java
mil.nga.giat.asam.map.SingleAsamMapActivity.java
mil.nga.giat.asam.map.SubregionMapActivity.java
mil.nga.giat.asam.model.AsamBean.java
mil.nga.giat.asam.model.AsamJsonParser.java
mil.nga.giat.asam.model.AsamMapClusterBean.java
mil.nga.giat.asam.model.LegalBean.java
mil.nga.giat.asam.model.SubregionBean.java
mil.nga.giat.asam.model.SubregionTextParser.java
mil.nga.giat.asam.model.TextQueryParametersBean.java
mil.nga.giat.asam.net.AsamWebService.java
mil.nga.giat.asam.util.AsamConstants.java
mil.nga.giat.asam.util.AsamListContainer.java
mil.nga.giat.asam.util.AsamLog.java
mil.nga.giat.asam.util.AsamUtils.java
mil.nga.giat.asam.util.CurrentSubregionHelper.java
mil.nga.giat.asam.util.ManifestMetaData.java
mil.nga.giat.asam.util.SyncTime.java
mil.nga.giat.asam.widget.AsamArrayAdapter.java