com.sentaroh.android.SMBSync2.ShortcutAutoSync.java Source code

Java tutorial

Introduction

Here is the source code for com.sentaroh.android.SMBSync2.ShortcutAutoSync.java

Source

package com.sentaroh.android.SMBSync2;

/*
The MIT License (MIT)
Copyright (c) 2011-2013 Sentaroh
    
Permission is hereby granted, free of charge, to any person obtaining a copy of 
this software and associated documentation files (the "Software"), to deal 
in the Software without restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so, subject to 
the following conditions:
    
The above copyright notice and this permission notice shall be included in all copies or 
substantial portions of the Software.
    
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
    
*/

import static com.sentaroh.android.SMBSync2.Constants.*;

import com.sentaroh.android.Utilities.ThemeUtil;

import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.FragmentActivity;
import android.view.Window;
import android.widget.Toast;

public class ShortcutAutoSync extends FragmentActivity {

    private Context context;

    private CommonUtilities util = null;
    private GlobalParameters mGp = null;

    private int restartStatus = 0;
    private boolean displayDialogRequired = false;

    @Override
    final protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        outState.putBoolean("displayDialogRequired", displayDialogRequired);
    };

    @Override
    final protected void onRestoreInstanceState(Bundle savedState) {
        super.onRestoreInstanceState(savedState);
        displayDialogRequired = savedState.getBoolean("displayDialogRequired", false);
        restartStatus = 2;
    };

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        //        setContentView(R.layout.activity_transrucent);

        //        envParms.loadSettingParms(context);
        //        util=new CommonUtilities(context, "ShortCutSleep", envParms);
        mGp = (GlobalParameters) getApplication();
        context = getApplicationContext();
        if (mGp.appContext == null) {
            mGp.appContext = this.getApplicationContext();
            mGp.initCommon(context);
            mGp.initSettingsParms(context);
            mGp.loadSettingsParms(context);
            mGp.setLogParms(mGp);
            mGp.themeColorList = ThemeUtil.getThemeColorList(this);
            mGp.uiHandler = new Handler();
        }

        util = new CommonUtilities(this.getApplicationContext(), "Shortcuut", mGp);

        util.addDebugMsg(1, "I", "onCreate entered restartStaus=" + restartStatus);
        // Application process is follow

    };

    @Override
    public void onStart() {
        super.onStart();
        util.addDebugMsg(1, "I", "onStart entered restartStaus=" + restartStatus);
    };

    @Override
    public void onRestart() {
        super.onStart();
        util.addDebugMsg(1, "I", "onRestart entered restartStaus=" + restartStatus);
    };

    final public void onResume() {
        super.onResume();
        util.addDebugMsg(1, "I", "onResume entered restartStaus=" + restartStatus);

        if (restartStatus == 0) {
            if (SyncService.isDuplicateRequest(mGp, SMBSYNC_SYNC_REQUEST_SHORTCUT)) {
                util.addLogMsg("W",
                        String.format(
                                context.getString(
                                        R.string.msgs_svc_received_start_request_ignored_duplicate_request),
                                SMBSYNC_SYNC_REQUEST_SHORTCUT));
                Toast.makeText(context,
                        String.format(
                                context.getString(
                                        R.string.msgs_svc_received_start_request_ignored_duplicate_request),
                                SMBSYNC_SYNC_REQUEST_SHORTCUT),
                        Toast.LENGTH_LONG).show();
            } else {
                Toast.makeText(context, context.getString(R.string.msgs_svc_received_start_request_from_shortcut),
                        Toast.LENGTH_LONG).show();
                Intent in = new Intent(context, SyncService.class);
                in.setAction(SMBSYNC_AUTO_SYNC_INTENT);
                context.startService(in);
            }
        }
        Handler hndl = new Handler();
        hndl.postDelayed(new Runnable() {
            @Override
            public void run() {
                finish();
            }
        }, 2000);
    };

    @Override
    public void onPause() {
        super.onPause();
        util.addDebugMsg(1, "I", "onPause entered restartStaus=" + restartStatus);
        // Application process is follow

    };

    @Override
    public void onStop() {
        super.onStop();
        util.addDebugMsg(1, "I", "onStop entered restartStaus=" + restartStatus);
        // Application process is follow

    };

    @Override
    public void onDestroy() {
        super.onDestroy();
        util.addDebugMsg(1, "I", "onDestroy entered restartStaus=" + restartStatus);
        // Application process is follow
        System.gc();
    };

    @Override
    public void onConfigurationChanged(final Configuration newConfig) {
        // Ignore orientation change to keep activity from restarting
        super.onConfigurationChanged(newConfig);
    };

}