Java tutorial
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 static com.sentaroh.android.SMBSync2.SchedulerConstants.*; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; import java.util.ArrayList; import android.Manifest; import android.annotation.SuppressLint; import android.annotation.TargetApi; import android.app.Activity; import android.app.Dialog; import android.content.ComponentName; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.content.ServiceConnection; import android.content.SharedPreferences; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; import android.content.res.Configuration; import android.graphics.Color; import android.net.Uri; import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.os.IBinder; import android.os.PowerManager; import android.os.RemoteException; import android.preference.PreferenceManager; import android.provider.Settings; import android.support.v4.view.ViewPager; import android.support.v7.app.ActionBar; import android.support.v7.app.AppCompatActivity; import android.text.ClipboardManager; import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.view.Window; import android.view.View.OnClickListener; import android.webkit.WebView; import android.widget.AdapterView; import android.widget.Button; import android.widget.CheckedTextView; import android.widget.ImageButton; import android.widget.LinearLayout; import android.widget.ListView; import android.widget.ProgressBar; import android.widget.TabHost; import android.widget.TabHost.OnTabChangeListener; import android.widget.TabWidget; import android.widget.TextView; import android.widget.Toast; import com.sentaroh.android.SMBSync2.R; import com.sentaroh.android.SMBSync2.ISvcCallback; import com.sentaroh.android.SMBSync2.ISvcClient; import com.sentaroh.android.SMBSync2.Log.LogFileListDialogFragment; import com.sentaroh.android.SMBSync2.Log.LogUtil; import com.sentaroh.android.Utilities.CallBackListener; import com.sentaroh.android.Utilities.SafUtil; import com.sentaroh.android.Utilities.SafCommonArea; import com.sentaroh.android.Utilities.ThemeUtil; import com.sentaroh.android.Utilities.NotifyEvent; import com.sentaroh.android.Utilities.NotifyEvent.NotifyEventListener; import com.sentaroh.android.Utilities.ThreadCtrl; import com.sentaroh.android.Utilities.ContextMenu.CustomContextMenu; import com.sentaroh.android.Utilities.Dialog.CommonDialog; import com.sentaroh.android.Utilities.Widget.CustomTabContentView; import com.sentaroh.android.Utilities.Widget.CustomViewPager; import com.sentaroh.android.Utilities.Widget.CustomViewPagerAdapter; import com.sentaroh.android.Utilities.ContextButton.ContextButtonUtil; @SuppressWarnings("deprecation") public class ActivityMain extends AppCompatActivity { private boolean isTaskTermination = false; // kill is disabled(enable is kill by onDestroy) private String packageVersionName = "Not found"; private TabHost mMainTabHost = null; private Context mContext = null; private AppCompatActivity mActivity = null; private GlobalParameters mGp = null; private SyncTaskUtility profUtil = null; private static CommonUtilities util = null; private CustomContextMenu ccMenu = null; private int restartType = NORMAL_START; private static int NORMAL_START = 0; private static int RESTART_WITH_OUT_INITIALYZE = 1; private static int RESTART_BY_KILLED = 2; // private static int RESTART_BY_DESTROYED=3; private static ServiceConnection mSvcConnection = null; private CommonDialog commonDlg = null; private static Handler mUiHandler = new Handler(); private ActionBar mActionBar = null; private SafCommonArea mSafCA = new SafCommonArea(); private String mCurrentTab = null; private boolean enableMainUi = true; @Override protected void onSaveInstanceState(Bundle out) { super.onSaveInstanceState(out); util.addDebugMsg(1, "I", "onSaveInstanceState entered."); out.putString("currentTab", mCurrentTab); }; @Override protected void onRestoreInstanceState(Bundle in) { super.onRestoreInstanceState(in); util.addDebugMsg(1, "I", "onRestoreInstanceState entered."); mCurrentTab = in.getString("currentTab"); // if (mGp.isApplicationIsRestartRequested) restartType=RESTART_BY_DESTROYED; // else restartType=RESTART_BY_KILLED; restartType = RESTART_BY_KILLED; }; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { mGp = (GlobalParameters) getApplication(); mContext = getApplicationContext(); mActivity = this; if (mGp.appContext == null) { mGp.appContext = this.getApplicationContext(); mGp.initCommon(mContext); mGp.initSettingsParms(mContext); mGp.loadSettingsParms(mContext); mGp.setLogParms(mGp); mGp.themeColorList = ThemeUtil.getThemeColorList(mActivity); mGp.uiHandler = new Handler(); } setTheme(mGp.applicationTheme); super.onCreate(savedInstanceState); setContentView(R.layout.main); mGp.themeColorList = ThemeUtil.getThemeColorList(mActivity); mActionBar = getSupportActionBar(); mActionBar.setDisplayShowHomeEnabled(false); mActionBar.setHomeButtonEnabled(false); util = new CommonUtilities(this.getApplicationContext(), "Main", mGp); util.addDebugMsg(1, "I", "onCreate entered, " + "resartStatus=" + restartType); Intent intent = new Intent(this, SyncService.class); startService(intent); SafUtil.initWorkArea(mContext, mSafCA, mGp.settingDebugLevel > 0); ccMenu = new CustomContextMenu(getResources(), getSupportFragmentManager()); commonDlg = new CommonDialog(this, getSupportFragmentManager()); checkRequiredPermissions(); profUtil = new SyncTaskUtility(util, this, commonDlg, ccMenu, mGp, getSupportFragmentManager()); mGp.msgListAdapter = new AdapterMessageList(this, R.layout.msg_list_item_view, mGp.msgList); if (mGp.syncTaskList == null) mGp.syncTaskList = SyncTaskUtility.createSyncTaskList(mContext, mGp, util, false, "", null); mGp.syncTaskAdapter = new AdapterSyncTask(mActivity, R.layout.sync_task_item_view, mGp.syncTaskList); if (mGp.syncHistoryList == null) mGp.syncHistoryList = util.loadHistoryList(); mGp.syncHistoryAdapter = new AdapterSyncHistory(mActivity, R.layout.sync_history_list_item_view, mGp.syncHistoryList); mCurrentTab = SMBSYNC_TAB_NAME_TASK; createTabView(); initAdapterAndView(); mGp.initJcifsOption(mContext); listSMBSyncOption(); getApplVersionName(); SchedulerUtil.sendTimerRequest(mContext, SCHEDULER_INTENT_SET_TIMER_IF_NOT_SET); setProfileContextButtonHide(); Thread th1 = new Thread() { @Override public void run() { util.addDebugMsg(1, "I", "Initialyze application specific directory started"); util.initAppSpecificExternalDirectory(mContext); util.addDebugMsg(1, "I", "Initialyze application specific directory ended"); } }; th1.start(); }; @SuppressLint("NewApi") @Override protected void onStart() { super.onStart(); util.addDebugMsg(1, "I", "onStart entered, " + "resartStatus=" + restartType); }; @Override protected void onResume() { super.onResume(); util.addDebugMsg(1, "I", "onResume entered, " + "resartStatus=" + restartType); // mGp.activityIsBackgroud=false; if (restartType == RESTART_WITH_OUT_INITIALYZE) { SchedulerUtil.setSchedulerInfo(mGp, mContext, null); if (!mGp.freezeMessageViewScroll) { mGp.uiHandler.post(new Runnable() { @Override public void run() { mGp.msgListView.setSelection(mGp.msgListAdapter.getCount() - 1); } }); } } else { NotifyEvent svc_ntfy = new NotifyEvent(mContext); svc_ntfy.setListener(new NotifyEventListener() { @Override public void positiveResponse(Context c, Object[] o) { setCallbackListener(); if (restartType == NORMAL_START) { setUiEnabled(); checkStorageStatus(); // util.addLogMsg("I",mContext.getString(R.string.msgs_smbsync_main_started)+" Version "+packageVersionName); // checkBatteryOptimization(); } else if (restartType == RESTART_BY_KILLED) { setUiEnabled(); restoreTaskData(); util.addLogMsg("W", mContext.getString(R.string.msgs_smbsync_main_restart_by_killed) + " Version " + packageVersionName); mMainTabHost.setCurrentTabByTag(SMBSYNC_TAB_NAME_STATUS); } setMessageContextButtonListener(); setMessageContextButtonNormalMode(); setProfileContextButtonListener(); setProfilelistItemClickListener(); setProfilelistLongClickListener(); setProfileContextButtonNormalMode(); setHistoryContextButtonListener(); setHistoryViewItemClickListener(); setHistoryViewLongClickListener(); setHistoryContextButtonNormalMode(); deleteTaskData(); SchedulerUtil.setSchedulerInfo(mGp, mContext, null); restartType = RESTART_WITH_OUT_INITIALYZE; reshowDialogWindow(); } @Override public void negativeResponse(Context c, Object[] o) { } }); openService(svc_ntfy); } }; @Override protected void onRestart() { super.onRestart(); util.addDebugMsg(1, "I", "onRestart entered, " + "resartStatus=" + restartType); }; @Override protected void onPause() { super.onPause(); util.addDebugMsg(1, "I", "onPause entered " + ",currentView=" + mCurrentTab + ", getChangingConfigurations=" + String.format("0x%08x", getChangingConfigurations())); // mGp.activityIsBackgroud=true; if (!isTaskTermination) saveTaskData(); }; @Override protected void onStop() { super.onStop(); util.addDebugMsg(1, "I", "onStop entered"); }; @Override public void onLowMemory() { util.addDebugMsg(1, "I", "onLowMemory entered"); }; @Override protected void onDestroy() { super.onDestroy(); util.addDebugMsg(1, "I", "onDestroy entered, " + "isFinishing=" + isFinishing() + ", changingConfigurations=" + String.format("0x%08x", getChangingConfigurations())); unsetCallbackListener(); mGp.msgListView.setAdapter(null); mGp.msgListAdapter = null; mGp.msgListView = null; mGp.syncHistoryAdapter = null; mGp.syncHistoryListView.setAdapter(null); mGp.syncHistoryListView = null; mGp.syncTaskAdapter = null; mGp.syncTaskListView.setAdapter(null); mGp.syncTaskListView = null; mGp.msgListAdapter = null; mGp.msgListView = null; mGp.syncHistoryAdapter = null; mGp.syncHistoryListView = null; mGp.syncTaskAdapter = null; mGp.syncTaskListView = null; deleteTaskData(); closeService(); LogUtil.flushLog(mContext, mGp); System.gc(); // if (isTaskTermination) { // unsetCallbackListener(); // mGp.msgListAdapter=null; // mGp.msgListView=null; // mGp.syncHistoryAdapter=null; // mGp.syncHistoryListView=null; // mGp.syncTaskListAdapter=null; // mGp.syncTaskListView=null; // deleteTaskData(); // closeService(); // LogUtil.flushLog(mContext,mGp); // } else { // unbindService(mSvcConnection); // mSvcConnection=null; // if (mGp.settingDebugLevel>0) { // util.addLogMsg("W","Unpredictable onDestroy was called" + // ", isFinishing="+isFinishing()+ // ", changingConfigurations="+String.format("0x%08x", getChangingConfigurations())); // } // LogUtil.flushLog(mContext, mGp); // } }; @SuppressLint("NewApi") private void checkBatteryOptimization() { if (Build.VERSION.SDK_INT >= 23) { Intent intent = new Intent(); String packageName = mContext.getPackageName(); PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE); if (pm.isIgnoringBatteryOptimizations(packageName)) intent.setAction(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS); else { intent.setAction(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS); intent.setData(Uri.parse("package:" + packageName)); } startActivity(intent); } }; class ViewSaveArea { public int current_tab_pos = 0; public int current_pager_pos = 0; public int prof_list_view_pos_x = 0, prof_list_view_pos_y = 0; public boolean prof_adapter_show_cb = false; public int msg_list_view_pos_x = 0, msg_list_view_pos_y = 0; public int sync_list_view_pos_x = 0, sync_list_view_pos_y = 0; public boolean sync_adapter_show_cb = false; public int prog_bar_view_visibility = ProgressBar.GONE, prog_spin_view_visibility = ProgressBar.GONE, confirm_view_visibility = ProgressBar.GONE; public String prog_prof = "", prog_msg = ""; public ArrayList<SyncHistoryItem> sync_hist_list = null; public String confirm_msg = ""; public String progress_bar_msg = ""; public int progress_bar_progress = 0, progress_bar_max = 0; public ButtonViewContent confirm_cancel = new ButtonViewContent(); public ButtonViewContent confirm_yes = new ButtonViewContent(); public ButtonViewContent confirm_yes_all = new ButtonViewContent(); public ButtonViewContent confirm_no = new ButtonViewContent(); public ButtonViewContent confirm_no_all = new ButtonViewContent(); public ButtonViewContent prog_bar_cancel = new ButtonViewContent(); public ButtonViewContent prog_bar_immed = new ButtonViewContent(); public ButtonViewContent prog_spin_cancel = new ButtonViewContent(); }; class ButtonViewContent { public String button_text = ""; public boolean button_visible = true, button_enabled = true, button_clickable = true; }; private void saveButtonStatus(Button btn, ButtonViewContent sv) { sv.button_text = btn.getText().toString(); sv.button_clickable = btn.isClickable(); sv.button_enabled = btn.isEnabled(); sv.button_visible = btn.isShown(); }; private void restoreButtonStatus(Button btn, ButtonViewContent sv, OnClickListener ocl) { btn.setText(sv.button_text); btn.setClickable(sv.button_clickable); btn.setEnabled(sv.button_enabled); // if (sv.button_visible) btn.setVisibility(Button.VISIBLE); // else btn.setVisibility(Button.GONE); btn.setOnClickListener(ocl); }; @Override public void onConfigurationChanged(final Configuration newConfig) { super.onConfigurationChanged(newConfig); if (util != null) { util.addDebugMsg(1, "I", "onConfigurationChanged Entered, ", "New orientation=" + newConfig.orientation + ", New language=", newConfig.locale.getLanguage()); } screenReload(false); }; private void screenReload(boolean force_reload) { util.addDebugMsg(1, "I", "screenReload Entered"); ViewSaveArea vsa = null; vsa = saveViewContent(); releaseImageResource(); setContentView(R.layout.main); mActionBar = getSupportActionBar(); mGp.syncHistoryListView.setAdapter(null); mGp.syncTaskListView.setAdapter(null); ArrayList<SyncTaskItem> pfl = mGp.syncTaskAdapter.getArrayList(); mGp.msgListView.setAdapter(null); ArrayList<MsgListItem> mfl = mGp.msgListAdapter.getMessageList(); createTabView(); mMainTabHost.setOnTabChangedListener(null); mGp.syncTaskAdapter = new AdapterSyncTask(mActivity, R.layout.sync_task_item_view, pfl); mGp.syncTaskAdapter.setShowCheckBox(vsa.prof_adapter_show_cb); mGp.syncTaskAdapter.notifyDataSetChanged(); mGp.msgListAdapter = new AdapterMessageList(this, R.layout.msg_list_item_view, mfl); mGp.syncHistoryAdapter = new AdapterSyncHistory(mActivity, R.layout.sync_history_list_item_view, vsa.sync_hist_list); mGp.syncHistoryAdapter.setShowCheckBox(vsa.sync_adapter_show_cb); mGp.syncHistoryAdapter.notifyDataSetChanged(); initAdapterAndView(); restoreViewContent(vsa); mMainTabHost.setOnTabChangedListener(new MainOnTabChange()); setMessageContextButtonListener(); setMessageContextButtonNormalMode(); setProfileContextButtonListener(); setProfilelistItemClickListener(); setProfilelistLongClickListener(); // setMsglistLongClickListener(); setHistoryContextButtonListener(); setHistoryViewItemClickListener(); setHistoryViewLongClickListener(); if (mCurrentTab.equals(SMBSYNC_TAB_NAME_TASK)) { if (mGp.syncHistoryAdapter.isShowCheckBox()) setHistoryContextButtonSelectMode(); else setHistoryContextButtonNormalMode(); if (mGp.syncTaskAdapter.isShowCheckBox()) setProfileContextButtonSelectMode(); else setProfileContextButtonNormalMode(); } else if (mCurrentTab.equals(SMBSYNC_TAB_NAME_HIST)) { if (mGp.syncTaskAdapter.isShowCheckBox()) setProfileContextButtonSelectMode(); else setProfileContextButtonNormalMode(); if (mGp.syncHistoryAdapter.isShowCheckBox()) setHistoryContextButtonSelectMode(); else setHistoryContextButtonNormalMode(); } if (isUiEnabled()) setUiEnabled(); else setUiDisabled(); vsa = null; } private int newProfileListViewPos = -1; private ViewSaveArea saveViewContent() { ViewSaveArea vsa = new ViewSaveArea(); vsa.current_tab_pos = mMainTabHost.getCurrentTab(); vsa.current_pager_pos = mMainViewPager.getCurrentItem(); vsa.prof_list_view_pos_x = mGp.syncTaskListView.getFirstVisiblePosition(); if (mGp.syncTaskListView.getChildAt(0) != null) vsa.prof_list_view_pos_y = mGp.syncTaskListView.getChildAt(0).getTop(); vsa.prof_adapter_show_cb = mGp.syncTaskAdapter.isShowCheckBox(); vsa.msg_list_view_pos_x = mGp.msgListView.getFirstVisiblePosition(); if (mGp.msgListView.getChildAt(0) != null) vsa.msg_list_view_pos_y = mGp.msgListView.getChildAt(0).getTop(); vsa.sync_list_view_pos_x = mGp.syncHistoryListView.getFirstVisiblePosition(); if (mGp.syncHistoryListView.getChildAt(0) != null) vsa.sync_list_view_pos_y = mGp.syncHistoryListView.getChildAt(0).getTop(); vsa.sync_adapter_show_cb = mGp.syncHistoryAdapter.isShowCheckBox(); vsa.prog_prof = mGp.progressSpinSyncprof.getText().toString(); vsa.prog_msg = mGp.progressSpinMsg.getText().toString(); vsa.progress_bar_progress = mGp.progressBarPb.getProgress(); vsa.progress_bar_max = mGp.progressBarPb.getMax(); vsa.prog_bar_view_visibility = mGp.progressBarView.getVisibility(); vsa.confirm_view_visibility = mGp.confirmView.getVisibility(); vsa.prog_spin_view_visibility = mGp.progressSpinView.getVisibility(); // Log.v("","prog_bar="+vsa.prog_bar_view_visibility+ // ", prog_spin="+vsa.prog_spin_view_visibility+", confirm="+vsa.confirm_view_visibility); saveButtonStatus(mGp.confirmCancel, vsa.confirm_cancel); saveButtonStatus(mGp.confirmYes, vsa.confirm_yes); saveButtonStatus(mGp.confirmYesAll, vsa.confirm_yes_all); saveButtonStatus(mGp.confirmNo, vsa.confirm_no); saveButtonStatus(mGp.confirmNoAll, vsa.confirm_no_all); saveButtonStatus(mGp.progressBarCancel, vsa.prog_bar_cancel); saveButtonStatus(mGp.progressSpinCancel, vsa.prog_spin_cancel); saveButtonStatus(mGp.progressBarImmed, vsa.prog_bar_immed); vsa.confirm_msg = mGp.confirmMsg.getText().toString(); vsa.progress_bar_msg = mGp.progressBarMsg.getText().toString(); vsa.sync_hist_list = mGp.syncHistoryAdapter.getSyncHistoryList(); return vsa; }; private void restoreViewContent(ViewSaveArea vsa) { mMainTabHost.setCurrentTab(vsa.current_tab_pos); mMainViewPager.setCurrentItem(vsa.current_pager_pos); mGp.syncTaskListView.setSelectionFromTop(vsa.prof_list_view_pos_x, vsa.prof_list_view_pos_y); mGp.msgListView.setSelectionFromTop(vsa.msg_list_view_pos_x, vsa.msg_list_view_pos_y); mGp.syncHistoryListView.setSelectionFromTop(vsa.sync_list_view_pos_x, vsa.sync_list_view_pos_y); mGp.confirmMsg.setText(vsa.confirm_msg); restoreButtonStatus(mGp.confirmCancel, vsa.confirm_cancel, mGp.confirmCancelListener); restoreButtonStatus(mGp.confirmYes, vsa.confirm_yes, mGp.confirmYesListener); restoreButtonStatus(mGp.confirmYesAll, vsa.confirm_yes_all, mGp.confirmYesAllListener); restoreButtonStatus(mGp.confirmNo, vsa.confirm_no, mGp.confirmNoListener); restoreButtonStatus(mGp.confirmNoAll, vsa.confirm_no_all, mGp.confirmNoAllListener); restoreButtonStatus(mGp.progressBarCancel, vsa.prog_bar_cancel, mGp.progressBarCancelListener); restoreButtonStatus(mGp.progressSpinCancel, vsa.prog_spin_cancel, mGp.progressSpinCancelListener); restoreButtonStatus(mGp.progressBarImmed, vsa.prog_bar_immed, mGp.progressBarImmedListener); mGp.progressBarMsg.setText(vsa.progress_bar_msg); mGp.progressBarPb.setMax(vsa.progress_bar_max); mGp.progressBarPb.setProgress(vsa.progress_bar_progress); mGp.progressSpinSyncprof.setText(vsa.prog_prof); mGp.progressSpinMsg.setText(vsa.prog_msg); mGp.scheduleInfoView.setText(mGp.scheduleInfoText); if (vsa.prog_bar_view_visibility != LinearLayout.GONE) { mGp.progressBarView.bringToFront(); mGp.progressBarView.setBackgroundColor(mGp.themeColorList.dialog_msg_background_color); mGp.progressBarView.setVisibility(LinearLayout.VISIBLE); } else mGp.progressBarView.setVisibility(LinearLayout.GONE); if (vsa.prog_spin_view_visibility != LinearLayout.GONE) { mGp.progressSpinView.bringToFront(); mGp.progressSpinView.setBackgroundColor(mGp.themeColorList.dialog_msg_background_color); mGp.progressSpinView.setVisibility(LinearLayout.VISIBLE); } else mGp.progressSpinView.setVisibility(LinearLayout.GONE); if (vsa.confirm_view_visibility != LinearLayout.GONE) { mGp.confirmView.setBackgroundColor(mGp.themeColorList.dialog_msg_background_color); mGp.confirmView.setVisibility(LinearLayout.VISIBLE); mGp.confirmView.bringToFront(); } else { mGp.confirmView.setVisibility(LinearLayout.GONE); } }; private void initAdapterAndView() { if (isUiEnabled()) mGp.msgListView.setFastScrollEnabled(true); mGp.msgListView.setAdapter(mGp.msgListAdapter); mGp.msgListView.setDrawingCacheEnabled(true); mGp.msgListView.setClickable(true); mGp.msgListView.setFocusable(true); mGp.msgListView.setFocusableInTouchMode(true); mGp.msgListView.setSelected(true); mGp.syncTaskListView.setAdapter(mGp.syncTaskAdapter); mGp.syncTaskListView.setDrawingCacheEnabled(true); mGp.syncTaskListView.setClickable(true); mGp.syncTaskListView.setFocusable(true); mGp.syncTaskListView.setFocusableInTouchMode(true); mGp.syncTaskListView.setSelected(true); mGp.syncHistoryListView.setAdapter(mGp.syncHistoryAdapter); mGp.syncHistoryAdapter.notifyDataSetChanged(); mGp.syncHistoryListView.setClickable(true); mGp.syncHistoryListView.setFocusable(true); // mGp.syncHistoryListView.setFastScrollEnabled(true); mGp.syncHistoryListView.setFocusableInTouchMode(true); // mGp.syncHistoryListView.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_INSET); // setFastScrollListener(mGp.syncHistoryListView); }; private void getApplVersionName() { try { String packegeName = getPackageName(); PackageInfo packageInfo = getPackageManager().getPackageInfo(packegeName, PackageManager.GET_META_DATA); packageVersionName = packageInfo.versionName; } catch (NameNotFoundException e) { util.addDebugMsg(1, "I", "SMBSync package can not be found"); } }; private LinearLayout mProfileView; private LinearLayout mHistoryView; private LinearLayout mMessageView; private CustomViewPager mMainViewPager; private CustomViewPagerAdapter mMainViewPagerAdapter; private TabWidget mMainTabWidget; @SuppressLint("InflateParams") @TargetApi(Build.VERSION_CODES.HONEYCOMB) private void createTabView() { mMainTabHost = (TabHost) findViewById(android.R.id.tabhost); mMainTabHost.setup(); mMainTabWidget = (TabWidget) findViewById(android.R.id.tabs); if (Build.VERSION.SDK_INT >= 11) { mMainTabWidget.setStripEnabled(false); mMainTabWidget.setShowDividers(LinearLayout.SHOW_DIVIDER_NONE); } CustomTabContentView tabViewProf = new CustomTabContentView(this, getString(R.string.msgs_tab_name_prof)); mMainTabHost.addTab(mMainTabHost.newTabSpec(SMBSYNC_TAB_NAME_TASK).setIndicator(tabViewProf) .setContent(android.R.id.tabcontent)); CustomTabContentView tabViewHist = new CustomTabContentView(this, getString(R.string.msgs_tab_name_history)); mMainTabHost.addTab(mMainTabHost.newTabSpec(SMBSYNC_TAB_NAME_HIST).setIndicator(tabViewHist) .setContent(android.R.id.tabcontent)); CustomTabContentView tabViewMsg = new CustomTabContentView(this, getString(R.string.msgs_tab_name_msg)); mMainTabHost.addTab(mMainTabHost.newTabSpec(SMBSYNC_TAB_NAME_STATUS).setIndicator(tabViewMsg) .setContent(android.R.id.tabcontent)); LinearLayout ll_main = (LinearLayout) findViewById(R.id.main_view); ll_main.setBackgroundColor(mGp.themeColorList.window_background_color_content); LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); mProfileView = (LinearLayout) vi.inflate(R.layout.main_profile, null); mProfileView.setBackgroundColor(mGp.themeColorList.window_background_color_content); mHistoryView = (LinearLayout) vi.inflate(R.layout.main_history, null); mHistoryView.setBackgroundColor(mGp.themeColorList.window_background_color_content); mMessageView = (LinearLayout) vi.inflate(R.layout.main_msg, null); mMessageView.setBackgroundColor(mGp.themeColorList.window_background_color_content); mGp.msgListView = (ListView) mMessageView.findViewById(R.id.main_msg_view_list); mGp.syncTaskListView = (ListView) mProfileView.findViewById(R.id.main_profile_view_list); mGp.syncHistoryListView = (ListView) mHistoryView.findViewById(R.id.main_history_list); mGp.scheduleInfoView = (TextView) findViewById(R.id.main_schedule_view_info); mGp.scheduleInfoView.setTextColor(mGp.themeColorList.text_color_primary); mGp.confirmView = (LinearLayout) findViewById(R.id.main_dialog_confirm_view); mGp.confirmView.setBackgroundColor(mGp.themeColorList.dialog_msg_background_color); mGp.confirmView.setVisibility(LinearLayout.GONE); mGp.confirmMsg = (TextView) findViewById(R.id.main_dialog_confirm_msg); mGp.confirmMsg.setTextColor(mGp.themeColorList.text_color_primary); mGp.confirmCancel = (Button) findViewById(R.id.main_dialog_confirm_sync_cancel); setButtonColor(mGp.confirmCancel); if (mGp.themeColorList.theme_is_light) mGp.confirmCancel.setTextColor(mGp.themeColorList.text_color_primary); mGp.confirmYes = (Button) findViewById(R.id.copy_delete_confirm_yes); setButtonColor(mGp.confirmYes); mGp.confirmYes.setTextColor(mGp.themeColorList.text_color_primary); mGp.confirmNo = (Button) findViewById(R.id.copy_delete_confirm_no); setButtonColor(mGp.confirmNo); mGp.confirmNo.setTextColor(mGp.themeColorList.text_color_primary); mGp.confirmYesAll = (Button) findViewById(R.id.copy_delete_confirm_yesall); setButtonColor(mGp.confirmYesAll); mGp.confirmYesAll.setTextColor(mGp.themeColorList.text_color_primary); mGp.confirmNoAll = (Button) findViewById(R.id.copy_delete_confirm_noall); setButtonColor(mGp.confirmNoAll); mGp.confirmNoAll.setTextColor(mGp.themeColorList.text_color_primary); mGp.progressBarView = (LinearLayout) findViewById(R.id.main_dialog_progress_bar_view); mGp.progressBarView.setBackgroundColor(mGp.themeColorList.dialog_msg_background_color); mGp.progressBarView.setVisibility(LinearLayout.GONE); mGp.progressBarMsg = (TextView) findViewById(R.id.main_dialog_progress_bar_msg); mGp.progressBarMsg.setTextColor(mGp.themeColorList.text_color_primary); mGp.progressBarPb = (ProgressBar) findViewById(R.id.main_dialog_progress_bar_progress); mGp.progressBarCancel = (Button) findViewById(R.id.main_dialog_progress_bar_btn_cancel); setButtonColor(mGp.progressBarCancel); if (mGp.themeColorList.theme_is_light) mGp.progressBarCancel.setTextColor(mGp.themeColorList.text_color_primary); mGp.progressBarImmed = (Button) findViewById(R.id.main_dialog_progress_bar_btn_immediate); setButtonColor(mGp.progressBarImmed); if (mGp.themeColorList.theme_is_light) mGp.progressBarImmed.setTextColor(mGp.themeColorList.text_color_primary); mGp.progressSpinView = (LinearLayout) findViewById(R.id.main_dialog_progress_spin_view); mGp.progressSpinView.setBackgroundColor(mGp.themeColorList.dialog_msg_background_color); mGp.progressSpinView.setVisibility(LinearLayout.GONE); mGp.progressSpinSyncprof = (TextView) findViewById(R.id.main_dialog_progress_spin_syncprof); mGp.progressSpinSyncprof.setTextColor(mGp.themeColorList.text_color_primary); mGp.progressSpinMsg = (TextView) findViewById(R.id.main_dialog_progress_spin_syncmsg); mGp.progressSpinMsg.setTextColor(mGp.themeColorList.text_color_primary); mGp.progressSpinCancel = (Button) findViewById(R.id.main_dialog_progress_spin_btn_cancel); setButtonColor(mGp.progressSpinCancel); if (mGp.themeColorList.theme_is_light) mGp.progressSpinCancel.setTextColor(mGp.themeColorList.text_color_primary); createContextView(); mMainViewPagerAdapter = new CustomViewPagerAdapter(this, new View[] { mProfileView, mHistoryView, mMessageView }); mMainViewPager = (CustomViewPager) findViewById(R.id.main_view_pager); // mMainViewPager.setBackgroundColor(mThemeColorList.window_color_background); mMainViewPager.setAdapter(mMainViewPagerAdapter); mMainViewPager.setOnPageChangeListener(new MainPageChangeListener()); if (restartType == NORMAL_START) { mMainTabHost.setCurrentTabByTag(SMBSYNC_TAB_NAME_TASK); mMainViewPager.setCurrentItem(0); } mMainTabHost.setOnTabChangedListener(new MainOnTabChange()); }; private void setButtonColor(Button btn) { if (Build.VERSION.SDK_INT < 11) { btn.setBackgroundColor(Color.DKGRAY); } }; private class MainOnTabChange implements OnTabChangeListener { @Override public void onTabChanged(String tabId) { util.addDebugMsg(2, "I", "onTabchanged entered. tab=" + tabId + ",v=" + mCurrentTab); mActionBar.setIcon(R.drawable.smbsync); mActionBar.setHomeButtonEnabled(false); mActionBar.setTitle(R.string.app_name); mMainViewPager.setCurrentItem(mMainTabHost.getCurrentTab()); if (mGp.syncTaskAdapter.isShowCheckBox()) { mGp.syncTaskAdapter.setShowCheckBox(false); mGp.syncTaskAdapter.setAllItemChecked(false); mGp.syncTaskAdapter.notifyDataSetChanged(); setProfileContextButtonNormalMode(); } if (mGp.syncHistoryAdapter.isShowCheckBox()) { mGp.syncHistoryAdapter.setShowCheckBox(false); mGp.syncHistoryAdapter.setAllItemChecked(false); mGp.syncHistoryAdapter.notifyDataSetChanged(); setHistoryContextButtonNormalMode(); } if (tabId.equals(SMBSYNC_TAB_NAME_TASK) && newProfileListViewPos != -1) { mGp.syncTaskListView.post(new Runnable() { @Override public void run() { mGp.syncTaskListView.setSelection(newProfileListViewPos); newProfileListViewPos = -1; } }); } else if (tabId.equals(SMBSYNC_TAB_NAME_STATUS)) { if (!mGp.freezeMessageViewScroll) { mGp.uiHandler.post(new Runnable() { @Override public void run() { mGp.msgListView.setSelection(mGp.msgListAdapter.getCount() - 1); } }); } } mCurrentTab = tabId; refreshOptionMenu(); }; }; private class MainPageChangeListener implements ViewPager.OnPageChangeListener { @Override public void onPageSelected(int position) { // util.addDebugMsg(2,"I","onPageSelected entered, pos="+position); mMainTabWidget.setCurrentTab(position); mMainTabHost.setCurrentTab(position); } @Override public void onPageScrollStateChanged(int state) { // util.addDebugMsg(2,"I","onPageScrollStateChanged entered, state="+state); } @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { // util.addDebugMsg(2,"I","onPageScrolled entered, pos="+position); } }; @Override public boolean onCreateOptionsMenu(Menu menu) { util.addDebugMsg(2, "I", "onCreateOptionsMenu entered"); MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.menu_top, menu); return true;//super.onCreateOptionsMenu(menu); }; @Override public boolean onPrepareOptionsMenu(Menu menu) { util.addDebugMsg(2, "I", "onPrepareOptionsMenu entered, isUiEnabled()=" + isUiEnabled()); // menu.findItem(R.id.menu_top_scheduler).setVisible(false); if (isUiEnabled()) { menu.findItem(R.id.menu_top_housekeep).setEnabled(true); if (mGp.syncThreadActive) menu.findItem(R.id.menu_top_housekeep).setVisible(false); else menu.findItem(R.id.menu_top_housekeep).setVisible(true); menu.findItem(R.id.menu_top_sync).setVisible(true); menu.findItem(R.id.menu_top_settings).setEnabled(true); // menu.findItem(R.id.menu_top_scheduler).setVisible(true);//.setEnabled(true); if (!mGp.externalStorageIsMounted) { menu.findItem(R.id.menu_top_browse_log).setEnabled(false); menu.findItem(R.id.menu_top_export).setEnabled(false); menu.findItem(R.id.menu_top_import).setEnabled(false); menu.findItem(R.id.menu_top_log_management).setEnabled(false); } else { if (!mGp.settingLogOption) menu.findItem(R.id.menu_top_browse_log).setVisible(false); else menu.findItem(R.id.menu_top_browse_log).setVisible(true); menu.findItem(R.id.menu_top_export).setEnabled(true); menu.findItem(R.id.menu_top_import).setEnabled(true); menu.findItem(R.id.menu_top_log_management).setEnabled(true); } } else { menu.findItem(R.id.menu_top_sync).setVisible(false); if (!mGp.settingLogOption) menu.findItem(R.id.menu_top_browse_log).setVisible(false); else menu.findItem(R.id.menu_top_browse_log).setVisible(true); menu.findItem(R.id.menu_top_browse_log).setEnabled(true); if (!mGp.externalStorageIsMounted) { menu.findItem(R.id.menu_top_browse_log).setEnabled(false); } if (!mGp.settingLogOption) { menu.findItem(R.id.menu_top_browse_log).setEnabled(false); } // Log.v("","ena="+menu.findItem(R.id.menu_top_browse_log).isEnabled()); menu.findItem(R.id.menu_top_export).setEnabled(false); menu.findItem(R.id.menu_top_import).setEnabled(false); menu.findItem(R.id.menu_top_about).setEnabled(false); menu.findItem(R.id.menu_top_settings).setEnabled(false); menu.findItem(R.id.menu_top_log_management).setEnabled(false); menu.findItem(R.id.menu_top_housekeep).setEnabled(false); } return super.onPrepareOptionsMenu(menu); }; private boolean mScheduleEditorAvailable = true; @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: processHomeButtonPress(); return true; case R.id.menu_top_sync: if (enableMainUi) { if (SyncTaskUtility.getSyncTaskSelectedItemCount(mGp.syncTaskAdapter) > 0) { syncSelectedProfile(); } else { syncActiveProfile(); } SyncTaskUtility.setAllSyncTaskToUnchecked(true, mGp.syncTaskAdapter); setProfileContextButtonNormalMode(); } return true; case R.id.menu_top_browse_log: invokeLogFileBrowser(); setContextButtonNormalMode(); return true; case R.id.menu_top_export: profUtil.exportSyncTaskListDlg(mGp.internalRootDirectory, "/" + APPLICATION_TAG, "profile.txt"); setContextButtonNormalMode(); return true; case R.id.menu_top_import: importProfileAndParms(); setContextButtonNormalMode(); return true; case R.id.menu_top_log_management: invokeLogManagement(); setContextButtonNormalMode(); return true; case R.id.menu_top_scheduler: if (mScheduleEditorAvailable) { mScheduleEditorAvailable = false; SchedulerEditor sm = new SchedulerEditor(util, this, this, commonDlg, ccMenu, mGp); sm.initDialog(); setContextButtonNormalMode(); mUiHandler.postDelayed(new Runnable() { @Override public void run() { mScheduleEditorAvailable = true; } }, 1000); } return true; case R.id.menu_top_about: aboutSMBSync(); setContextButtonNormalMode(); return true; case R.id.menu_top_settings: invokeSettingsActivity(); setContextButtonNormalMode(); return true; case R.id.menu_top_kill: killTerminateApplication(); setContextButtonNormalMode(); return true; case R.id.menu_top_housekeep: houseKeepLocalFileLastModList(); return true; } if (isUiEnabled()) { } return false; }; private void housekeepThreadStarted() { util.addDebugMsg(1, "I", "housekeepThreadStarted entered"); setUiDisabled(); mGp.progressSpinView.setVisibility(LinearLayout.VISIBLE); mGp.progressSpinView.setBackgroundColor(mGp.themeColorList.dialog_msg_background_color); mGp.progressSpinView.bringToFront(); mGp.progressSpinSyncprof.setVisibility(TextView.GONE); mGp.progressSpinMsg.setText(getString(R.string.msgs_progress_spin_dlg_housekeep_running)); mGp.progressSpinCancel.setText(getString(R.string.msgs_progress_spin_dlg_housekeep_cancel)); mGp.progressSpinCancel.setEnabled(true); // CANCEL? mGp.progressSpinCancelListener = new View.OnClickListener() { public void onClick(View v) { NotifyEvent ntfy = new NotifyEvent(mContext); ntfy.setListener(new NotifyEventListener() { @Override public void positiveResponse(Context c, Object[] o) { mTcHousekeep.setDisabled(); mGp.progressSpinCancel.setText(getString(R.string.msgs_progress_dlg_canceling)); mGp.progressSpinCancel.setEnabled(false); } @Override public void negativeResponse(Context c, Object[] o) { } }); commonDlg.showCommonDialog(true, "W", getString(R.string.msgs_progress_spin_dlg_housekeep_cancel_confirm), "", ntfy); } }; mGp.progressSpinCancel.setOnClickListener(mGp.progressSpinCancelListener); mGp.msgListView.setFastScrollEnabled(false); LogUtil.flushLog(mContext, mGp); }; private void housekeepThreadEnded() { util.addDebugMsg(1, "I", "housekeepThreadEnded ended"); LogUtil.flushLog(mContext, mGp); mGp.progressBarCancelListener = null; mGp.progressBarImmedListener = null; mGp.progressSpinCancelListener = null; mGp.progressBarCancel.setOnClickListener(null); mGp.progressSpinCancel.setOnClickListener(null); mGp.progressBarImmed.setOnClickListener(null); mGp.progressSpinView.setVisibility(LinearLayout.GONE); setUiEnabled(); }; private ThreadCtrl mTcHousekeep = null; private void houseKeepLocalFileLastModList() { NotifyEvent ntfy = new NotifyEvent(mContext); ntfy.setListener(new NotifyEventListener() { @Override public void positiveResponse(Context c, Object[] o) { mTcHousekeep = new ThreadCtrl(); Thread th2 = new Thread() { @Override public void run() { util.addLogMsg("I", mContext.getString(R.string.msgs_maintenance_last_mod_list_start_msg)); if (!mGp.syncThreadActive) { mGp.syncThreadEnabled = false; mUiHandler.post(new Runnable() { @Override public void run() { housekeepThreadStarted(); } }); ArrayList<FileLastModifiedEntryItem> mCurrLastModifiedList = new ArrayList<FileLastModifiedEntryItem>(); ArrayList<FileLastModifiedEntryItem> mNewLastModifiedList = new ArrayList<FileLastModifiedEntryItem>(); ArrayList<FileLastModifiedEntryItem> del_list = new ArrayList<FileLastModifiedEntryItem>(); LocalFileLastModified.loadLastModifiedList(mCurrLastModifiedList, mNewLastModifiedList); if (mCurrLastModifiedList.size() > 0) { for (FileLastModifiedEntryItem li : mCurrLastModifiedList) { if (!mTcHousekeep.isEnabled()) break; if (li.getFullFilePath().startsWith(mGp.internalRootDirectory)) { File lf = new File(li.getFullFilePath()); if (!lf.exists()) { del_list.add(li); util.addDebugMsg(1, "I", "Entery was deleted, fp=" + li.getFullFilePath()); } } } for (FileLastModifiedEntryItem li : del_list) { if (!mTcHousekeep.isEnabled()) break; mCurrLastModifiedList.remove(li); } } if (mTcHousekeep.isEnabled()) { if (del_list.size() > 0) LocalFileLastModified.saveLastModifiedList(mCurrLastModifiedList, mNewLastModifiedList); } String msg_txt = ""; if (mTcHousekeep.isEnabled()) msg_txt = mContext.getString(R.string.msgs_maintenance_last_mod_list_end_msg); else msg_txt = mContext.getString(R.string.msgs_maintenance_last_mod_list_cancel_msg); util.addLogMsg("I", msg_txt); commonDlg.showCommonDialog(false, "W", msg_txt, "", null); mGp.uiHandler.post(new Runnable() { @Override public void run() { housekeepThreadEnded(); mGp.syncThreadEnabled = true; } }); } else { util.addLogMsg("I", mContext.getString(R.string.msgs_maintenance_last_mod_list_can_not_start_msg)); commonDlg.showCommonDialog(false, "W", mContext.getString(R.string.msgs_maintenance_last_mod_list_can_not_start_msg), "", null); } } }; th2.setPriority(Thread.MAX_PRIORITY); th2.start(); } @Override public void negativeResponse(Context c, Object[] o) { } }); if (!mGp.syncThreadActive) { commonDlg.showCommonDialog(true, "W", mContext.getString(R.string.msgs_maintenance_last_mod_list_confirm_start_msg), "", ntfy); } else { util.addLogMsg("I", mContext.getString(R.string.msgs_maintenance_last_mod_list_can_not_start_msg)); commonDlg.showCommonDialog(false, "W", mContext.getString(R.string.msgs_maintenance_last_mod_list_can_not_start_msg), "", null); } }; private void setContextButtonNormalMode() { mActionBar.setIcon(R.drawable.smbsync); mActionBar.setHomeButtonEnabled(false); mActionBar.setTitle(R.string.app_name); mGp.syncTaskAdapter.setShowCheckBox(false); mGp.syncTaskAdapter.setAllItemChecked(false); mGp.syncTaskAdapter.notifyDataSetChanged(); setProfileContextButtonNormalMode(); mGp.syncHistoryAdapter.setShowCheckBox(false); mGp.syncHistoryAdapter.setAllItemChecked(false); mGp.syncHistoryAdapter.notifyDataSetChanged(); setHistoryContextButtonNormalMode(); }; private void processHomeButtonPress() { if (mCurrentTab.equals(SMBSYNC_TAB_NAME_TASK)) { if (mGp.syncTaskAdapter.isShowCheckBox()) { mGp.syncTaskAdapter.setShowCheckBox(false); mGp.syncTaskAdapter.notifyDataSetChanged(); setProfileContextButtonNormalMode(); } } else if (mCurrentTab.equals(SMBSYNC_TAB_NAME_STATUS)) { } else if (mCurrentTab.equals(SMBSYNC_TAB_NAME_HIST)) { if (mGp.syncHistoryAdapter.isShowCheckBox()) { mGp.syncHistoryAdapter.setShowCheckBox(false); mGp.syncHistoryAdapter.notifyDataSetChanged(); setHistoryItemUnselectAll(); setHistoryContextButtonNormalMode(); } } }; private void invokeLogManagement() { LogUtil.flushLog(mContext, mGp); LogFileListDialogFragment lfm = LogFileListDialogFragment.newInstance(false, getString(R.string.msgs_log_management_title)); lfm.showDialog(getSupportFragmentManager(), lfm, mGp, null); }; private void importProfileAndParms() { NotifyEvent ntfy = new NotifyEvent(this); ntfy.setListener(new NotifyEventListener() { @Override public void positiveResponse(Context c, Object[] o) { boolean[] parm = (boolean[]) o[0]; if (parm[0]) { reloadSettingParms(); SchedulerUtil.sendTimerRequest(mContext, SCHEDULER_INTENT_SET_TIMER); // if (mGp.syncTaskAdapter!=null) { // if (EditSyncTaskUtility.isProfileSelected(mGp.syncTaskAdapter)) setProfileContextButtonSelectMode(); // else setProfileContextButtonNormalMode(); // } } if (parm[1]) { SchedulerUtil.setSchedulerInfo(mGp, mContext, null); } setProfileContextButtonNormalMode(); mGp.syncTaskAdapter.setShowCheckBox(false); } @Override public void negativeResponse(Context c, Object[] o) { } }); profUtil.importSyncTaskListDlg(mGp.internalRootDirectory, "/" + APPLICATION_TAG, "profile.txt", ntfy); }; private CallBackListener onKeyCallBackListener = null; private void setOnKeyCallBackListener(CallBackListener cbl) { onKeyCallBackListener = cbl; }; private void unsetOnKeyCallBackListener() { onKeyCallBackListener = null; }; public boolean onKeyDown(int keyCode, KeyEvent event) { util.addDebugMsg(9, "i", "main onKeyDown enterd, kc=" + keyCode); switch (keyCode) { case KeyEvent.KEYCODE_BACK: if (onKeyCallBackListener != null) { if (!onKeyCallBackListener.onCallBack(mContext, event, null)) terminateApplication(); } else { terminateApplication(); } return true; // break; default: return super.onKeyDown(keyCode, event); // break; } }; private void checkStorageStatus() { if (!mGp.externalStorageIsMounted) { util.addLogMsg("W", getString(R.string.msgs_smbsync_main_no_external_storage)); commonDlg.showCommonDialog(false, "W", getString(R.string.msgs_smbsync_main_no_external_storage), "", null); } else { NotifyEvent ntfy = new NotifyEvent(mContext); ntfy.setListener(new NotifyEventListener() { @Override public void positiveResponse(Context c, Object[] o) { } @Override public void negativeResponse(Context c, Object[] o) { SyncTaskItem pli = SyncTaskUtility.getExternalSdcardUsedSyncProfile(mGp); String msg = String.format( mContext.getString(R.string.msgs_main_external_sdcard_select_required_cancel_msg), pli.getSyncTaskName()); commonDlg.showCommonDialog(false, "W", mContext.getString(R.string.msgs_main_external_sdcard_select_required_title), msg, null); } }); checkSafExternalSdcardTreeUri(ntfy); } }; @SuppressLint("InflateParams") private void aboutSMBSync() { final Dialog dialog = new Dialog(this); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setContentView(R.layout.about_dialog); final LinearLayout title_view = (LinearLayout) dialog.findViewById(R.id.about_dialog_title_view); final TextView title = (TextView) dialog.findViewById(R.id.about_dialog_title); title_view.setBackgroundColor(mGp.themeColorList.dialog_title_background_color); title.setTextColor(mGp.themeColorList.text_color_dialog_title); title.setText(getString(R.string.msgs_dlg_title_about) + "(Ver " + packageVersionName + ")"); // get our tabHost from the xml final TabHost tab_host = (TabHost) dialog.findViewById(R.id.about_tab_host); tab_host.setup(); final TabWidget tab_widget = (TabWidget) dialog.findViewById(android.R.id.tabs); if (Build.VERSION.SDK_INT >= 11) { tab_widget.setStripEnabled(false); tab_widget.setShowDividers(LinearLayout.SHOW_DIVIDER_NONE); } CustomTabContentView tabViewProf = new CustomTabContentView(this, getString(R.string.msgs_about_dlg_func_btn)); tab_host.addTab(tab_host.newTabSpec("func").setIndicator(tabViewProf).setContent(android.R.id.tabcontent)); CustomTabContentView tabViewHist = new CustomTabContentView(this, getString(R.string.msgs_about_dlg_change_btn)); tab_host.addTab( tab_host.newTabSpec("change").setIndicator(tabViewHist).setContent(android.R.id.tabcontent)); LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); LinearLayout ll_func = (LinearLayout) vi.inflate(R.layout.about_dialog_func, null); LinearLayout ll_change = (LinearLayout) vi.inflate(R.layout.about_dialog_change, null); final WebView func_view = (WebView) ll_func.findViewById(R.id.about_dialog_function); func_view.loadUrl("file:///android_asset/" + getString(R.string.msgs_dlg_title_about_func_desc)); func_view.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY); func_view.getSettings().setBuiltInZoomControls(true); final WebView change_view = (WebView) ll_change.findViewById(R.id.about_dialog_change_history); change_view.loadUrl("file:///android_asset/" + getString(R.string.msgs_dlg_title_about_change_desc)); change_view.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY); change_view.getSettings().setBuiltInZoomControls(true); final CustomViewPagerAdapter mAboutViewPagerAdapter = new CustomViewPagerAdapter(this, new WebView[] { func_view, change_view }); final CustomViewPager mAboutViewPager = (CustomViewPager) dialog.findViewById(R.id.about_view_pager); // mMainViewPager.setBackgroundColor(mThemeColorList.window_color_background); mAboutViewPager.setAdapter(mAboutViewPagerAdapter); mAboutViewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override public void onPageSelected(int position) { // util.addDebugMsg(2,"I","onPageSelected entered, pos="+position); tab_widget.setCurrentTab(position); tab_host.setCurrentTab(position); } @Override public void onPageScrollStateChanged(int state) { // util.addDebugMsg(2,"I","onPageScrollStateChanged entered, state="+state); } @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { // util.addDebugMsg(2,"I","onPageScrolled entered, pos="+position); } }); tab_host.setOnTabChangedListener(new OnTabChangeListener() { @Override public void onTabChanged(String tabId) { util.addDebugMsg(2, "I", "onTabchanged entered. tab=" + tabId); mAboutViewPager.setCurrentItem(tab_host.getCurrentTab()); } }); final Button btnOk = (Button) dialog.findViewById(R.id.about_dialog_btn_ok); CommonDialog.setDlgBoxSizeLimit(dialog, true); // OK? btnOk.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { dialog.dismiss(); } }); // Cancel? dialog.setOnCancelListener(new Dialog.OnCancelListener() { @Override public void onCancel(DialogInterface arg0) { btnOk.performClick(); } }); dialog.show(); }; private void terminateApplication() { if (mMainTabHost.getCurrentTabTag().equals(SMBSYNC_TAB_NAME_TASK)) {// if (mGp.syncTaskAdapter.isShowCheckBox()) { mGp.syncTaskAdapter.setShowCheckBox(false); mGp.syncTaskAdapter.notifyDataSetChanged(); setProfileContextButtonNormalMode(); return; } } else if (mMainTabHost.getCurrentTabTag().equals(SMBSYNC_TAB_NAME_STATUS)) { } else if (mMainTabHost.getCurrentTabTag().equals(SMBSYNC_TAB_NAME_HIST)) { if (mGp.syncHistoryAdapter.isShowCheckBox()) { mGp.syncHistoryAdapter.setShowCheckBox(false); mGp.syncHistoryAdapter.notifyDataSetChanged(); setHistoryItemUnselectAll(); setHistoryContextButtonNormalMode(); return; } } // util.addLogMsg("I",mContext.getString(R.string.msgs_smbsync_main_end)); isTaskTermination = true; // exit cleanly finish(); }; private void killTerminateApplication() { NotifyEvent ntfy = new NotifyEvent(mContext); ntfy.setListener(new NotifyEventListener() { @Override public void positiveResponse(Context c, Object[] o) { // terminateApplication(); deleteTaskData(); LogUtil.flushLog(mContext, mGp); android.os.Process.killProcess(android.os.Process.myPid()); } @Override public void negativeResponse(Context c, Object[] o) { } }); commonDlg.showCommonDialog(true, "W", mContext.getString(R.string.msgs_smnsync_main_kill_application), "", ntfy); }; private void reloadSettingParms() { util.addDebugMsg(1, "I", "reloadSettingParms entered"); String p_dir = mGp.settingLogMsgDir; boolean p_light_theme = mGp.themeIsLight; boolean p_log_option = mGp.settingLogOption; mGp.loadSettingsParms(mContext); mGp.setLogParms(mGp); if ((p_log_option && !mGp.settingLogOption) || (!p_log_option && mGp.settingLogOption)) util.resetLogReceiver(); if (!mGp.settingLogMsgDir.equals(p_dir) && mGp.settingLogOption) {// option was changed LogUtil.closeLog(mContext, mGp); } if ((p_light_theme && !mGp.themeIsLight) || (!p_light_theme && mGp.themeIsLight)) { setTheme(mGp.applicationTheme); mGp.themeColorList = ThemeUtil.getThemeColorList(mActivity); screenReload(false); } checkJcifsOptionChanged(); }; private void listSMBSyncOption() { util.addDebugMsg(1, "I", "SMBSync option :" + "debugLevel=" + mGp.settingDebugLevel + ", settingErrorOption=" + mGp.settingErrorOption + ", settingScreenOnOption=" + mGp.settingScreenOnOption + ", settingWifiLockRequired=" + mGp.settingWifiLockRequired + ", settingVibrateWhenSyncEnded=" + mGp.settingVibrateWhenSyncEnded + ", settingRingtoneWhenSyncEnded=" + mGp.settingRingtoneWhenSyncEnded + ", settingExitClean=" + mGp.settingExitClean + ", settingLogOption=" + mGp.settingLogOption + ", settingLogMsgDir=" + mGp.settingLogMsgDir + ", settingLogMsgFilename=" + mGp.settingLogMsgFilename + ", settiingLogGeneration=" + mGp.settingLogMaxFileCount + ", settingExportedProfileEncryptRequired=" + mGp.settingExportedProfileEncryptRequired); }; @SuppressLint("SdCardPath") private void invokeLogFileBrowser() { util.addDebugMsg(1, "I", "Invoke log file browser."); LogUtil.flushLog(mContext, mGp); if (mGp.settingLogOption) { Intent intent = new Intent(android.content.Intent.ACTION_VIEW); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setDataAndType(Uri.parse("file://" + LogUtil.getLogFilePath(mGp)), "text/plain"); startActivityForResult(intent, 1); } new Handler().postDelayed(new Runnable() { @Override public void run() { // enableBrowseLogFileMenu=true; } }, 1000); }; private void invokeSettingsActivity() { util.addDebugMsg(1, "I", "Invoke Settings."); Intent intent = null; intent = new Intent(this, ActivitySettings.class); startActivityForResult(intent, 0); }; private final int REQUEST_CODE_STORAGE_ACCESS = 40; @SuppressLint("InlinedApi") private void checkSafExternalSdcardTreeUri(final NotifyEvent p_ntfy) { if (profUtil.isExternalSdcardUsedByOutput()) { if (SafUtil.hasSafExternalSdcard(mSafCA) && !SafUtil.isValidSafExternalSdcardRootTreeUri(mSafCA)) { NotifyEvent ntfy = new NotifyEvent(mContext); ntfy.setListener(new NotifyEventListener() { @Override public void positiveResponse(Context c, Object[] o) { Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE); startActivityForResult(intent, REQUEST_CODE_STORAGE_ACCESS); // if (p_ntfy!=null) p_ntfy.notifyToListener(true, null); } @Override public void negativeResponse(Context c, Object[] o) { if (p_ntfy != null) p_ntfy.notifyToListener(false, null); } }); profUtil.showSelectSdcardMsg(ntfy, mContext.getString(R.string.msgs_main_external_sdcard_select_required_select_msg)); } else { if (p_ntfy != null) p_ntfy.notifyToListener(true, null); } } else { if (p_ntfy != null) p_ntfy.notifyToListener(true, null); } }; private final int REQUEST_PERMISSIONS_WRITE_EXTERNAL_STORAGE = 1; @SuppressLint("NewApi") private void checkRequiredPermissions() { if (Build.VERSION.SDK_INT >= 23) { util.addDebugMsg(1, "I", "Prermission WriteExternalStorage=" + checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) + ", WakeLock=" + checkSelfPermission(Manifest.permission.WAKE_LOCK)); if (checkSelfPermission( Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { NotifyEvent ntfy = new NotifyEvent(mContext); ntfy.setListener(new NotifyEventListener() { @Override public void positiveResponse(Context c, Object[] o) { requestPermissions(new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, REQUEST_PERMISSIONS_WRITE_EXTERNAL_STORAGE); } @Override public void negativeResponse(Context c, Object[] o) { NotifyEvent ntfy_term = new NotifyEvent(mContext); ntfy_term.setListener(new NotifyEventListener() { @Override public void positiveResponse(Context c, Object[] o) { isTaskTermination = true; finish(); } @Override public void negativeResponse(Context c, Object[] o) { } }); commonDlg.showCommonDialog(false, "W", mContext.getString(R.string.msgs_main_permission_external_storage_title), mContext.getString(R.string.msgs_main_permission_external_storage_denied_msg), ntfy_term); } }); commonDlg.showCommonDialog(false, "W", mContext.getString(R.string.msgs_main_permission_external_storage_title), mContext.getString(R.string.msgs_main_permission_external_storage_request_msg), ntfy); } } }; @Override public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { if (REQUEST_PERMISSIONS_WRITE_EXTERNAL_STORAGE == requestCode) { if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { } else { NotifyEvent ntfy_term = new NotifyEvent(mContext); ntfy_term.setListener(new NotifyEventListener() { @Override public void positiveResponse(Context c, Object[] o) { isTaskTermination = true; finish(); } @Override public void negativeResponse(Context c, Object[] o) { } }); commonDlg.showCommonDialog(false, "W", mContext.getString(R.string.msgs_main_permission_external_storage_title), mContext.getString(R.string.msgs_main_permission_external_storage_denied_msg), ntfy_term); } } } private NotifyEvent mSafSelectActivityNotify = null; protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == 0) { util.addDebugMsg(1, "I", "Return from Settings."); reloadSettingParms(); if (mGp.syncTaskAdapter.isShowCheckBox()) setProfileContextButtonSelectMode(); else setProfileContextButtonNormalMode(); } else if (requestCode == 1) { util.addDebugMsg(1, "I", "Return from browse log file."); } else if (requestCode == REQUEST_CODE_STORAGE_ACCESS) { util.addDebugMsg(1, "I", "Return from Storage Picker."); if (resultCode == Activity.RESULT_OK) { util.addDebugMsg(1, "I", "Intent=" + data.getData().toString()); if (SafUtil.isSafExternalSdcardRootTreeUri(mSafCA, data.getData())) { // String prev_uri_string=SafUtil.getSafExternalSdcardRootTreeUri(mSafCA); SafUtil.saveSafExternalSdcardRootTreeUri(mSafCA, data.getData().toString()); if (mSafSelectActivityNotify != null) mSafSelectActivityNotify.notifyToListener(true, null); } else { NotifyEvent ntfy = new NotifyEvent(mContext); ntfy.setListener(new NotifyEventListener() { @Override public void positiveResponse(Context c, Object[] o) { Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE); startActivityForResult(intent, REQUEST_CODE_STORAGE_ACCESS); } @Override public void negativeResponse(Context c, Object[] o) { } }); profUtil.showSelectSdcardMsg(ntfy, mContext.getString(R.string.msgs_main_external_sdcard_select_required_select_msg)); } } else { SyncTaskItem pli = SyncTaskUtility.getExternalSdcardUsedSyncProfile(mGp); String msg = String.format( mContext.getString(R.string.msgs_main_external_sdcard_select_required_cancel_msg), pli.getSyncTaskName()); commonDlg.showCommonDialog(false, "W", mContext.getString(R.string.msgs_main_external_sdcard_select_required_title), msg, null); } } }; private void setHistoryViewItemClickListener() { mGp.syncHistoryListView.setEnabled(true); mGp.syncHistoryListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { mGp.syncHistoryListView.setEnabled(false); SyncHistoryItem item = mGp.syncHistoryAdapter.getItem(position); if (mGp.syncHistoryAdapter.isShowCheckBox()) { item.isChecked = !item.isChecked; setHistoryContextButtonSelectMode(); mGp.syncHistoryListView.setEnabled(true); } else { if (!item.sync_result_file_path.equals("")) { Intent intent = new Intent(android.content.Intent.ACTION_VIEW); intent.setDataAndType(Uri.parse("file://" + item.sync_result_file_path), "text/plain"); startActivityForResult(intent, 1); } mUiHandler.postDelayed(new Runnable() { @Override public void run() { mGp.syncHistoryListView.setEnabled(true); } }, 1000); } mGp.syncHistoryAdapter.notifyDataSetChanged(); } }); NotifyEvent ntfy = new NotifyEvent(mContext); ntfy.setListener(new NotifyEventListener() { @Override public void positiveResponse(Context c, Object[] o) { setHistoryContextButtonSelectMode(); } @Override public void negativeResponse(Context c, Object[] o) { } }); mGp.syncHistoryAdapter.setNotifyCheckBoxEventHandler(ntfy); }; private void setHistoryViewLongClickListener() { mGp.syncHistoryListView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int pos, long arg3) { if (mGp.syncHistoryAdapter.isEmptyAdapter()) return true; if (!isUiEnabled()) return true; if (!mGp.syncHistoryAdapter.getItem(pos).isChecked) { if (mGp.syncHistoryAdapter.isAnyItemSelected()) { int down_sel_pos = -1, up_sel_pos = -1; int tot_cnt = mGp.syncHistoryAdapter.getCount(); if (pos + 1 <= tot_cnt) { for (int i = pos + 1; i < tot_cnt; i++) { if (mGp.syncHistoryAdapter.getItem(i).isChecked) { up_sel_pos = i; break; } } } if (pos > 0) { for (int i = pos; i >= 0; i--) { if (mGp.syncHistoryAdapter.getItem(i).isChecked) { down_sel_pos = i; break; } } } // Log.v("","up="+up_sel_pos+", down="+down_sel_pos); if (up_sel_pos != -1 && down_sel_pos == -1) { for (int i = pos; i < up_sel_pos; i++) mGp.syncHistoryAdapter.getItem(i).isChecked = true; } else if (up_sel_pos != -1 && down_sel_pos != -1) { for (int i = down_sel_pos + 1; i < up_sel_pos; i++) mGp.syncHistoryAdapter.getItem(i).isChecked = true; } else if (up_sel_pos == -1 && down_sel_pos != -1) { for (int i = down_sel_pos + 1; i <= pos; i++) mGp.syncHistoryAdapter.getItem(i).isChecked = true; } mGp.syncHistoryAdapter.notifyDataSetChanged(); } else { mGp.syncHistoryAdapter.setShowCheckBox(true); mGp.syncHistoryAdapter.getItem(pos).isChecked = true; mGp.syncHistoryAdapter.notifyDataSetChanged(); } setHistoryContextButtonSelectMode(); } return true; } }); }; private void setHistoryContextButtonListener() { mContextHistoryButtonMoveTop.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { setContextButtonEnabled(mContextHistoryButtonMoveTop, false); mGp.syncHistoryListView.setSelection(0); setContextButtonEnabled(mContextHistoryButtonMoveTop, true); } }); ContextButtonUtil.setButtonLabelListener(mContext, mContextHistoryButtonMoveTop, mContext.getString(R.string.msgs_hist_cont_label_move_top)); mContextHistoryButtonMoveBottom.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { setContextButtonEnabled(mContextHistoryButtonMoveBottom, false); mGp.syncHistoryListView.setSelection(mGp.syncHistoryAdapter.getCount() - 1); setContextButtonEnabled(mContextHistoryButtonMoveBottom, true); } }); ContextButtonUtil.setButtonLabelListener(mContext, mContextHistoryButtonMoveBottom, mContext.getString(R.string.msgs_hist_cont_label_move_bottom)); mContextHistoryButtonDeleteHistory.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (enableMainUi) { confirmDeleteHistory(); } } }); ContextButtonUtil.setButtonLabelListener(mContext, mContextHistoryButtonDeleteHistory, mContext.getString(R.string.msgs_hist_cont_label_delete)); final Toast toast = Toast.makeText(mContext, mContext.getString(R.string.msgs_sync_history_copy_completed), Toast.LENGTH_SHORT); toast.setDuration(1500); mContextHistoryButtonHistiryCopyClipboard.setOnClickListener(new OnClickListener() { private long last_show_time = 0; @Override public void onClick(View v) { setContextButtonEnabled(mContextHistoryButtonHistiryCopyClipboard, false); if (enableMainUi) { ClipboardManager cm = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); StringBuilder out = new StringBuilder(256); for (int i = 0; i < mGp.syncHistoryAdapter.getCount(); i++) { if (mGp.syncHistoryAdapter.getItem(i).isChecked) { SyncHistoryItem hli = mGp.syncHistoryAdapter.getItem(i); out.append(hli.sync_date).append(" "); out.append(hli.sync_time).append(" "); out.append(hli.sync_prof).append("\n"); if (hli.sync_status == SyncHistoryItem.SYNC_STATUS_SUCCESS) { out.append(mContext.getString(R.string.msgs_sync_history_status_success)) .append("\n"); } else if (hli.sync_status == SyncHistoryItem.SYNC_STATUS_ERROR) { out.append(mContext.getString(R.string.msgs_sync_history_status_error)) .append("\n"); } else if (hli.sync_status == SyncHistoryItem.SYNC_STATUS_CANCEL) { out.append(mContext.getString(R.string.msgs_sync_history_status_cancel)) .append("\n"); } out.append(mContext.getString(R.string.msgs_sync_history_count_copied)) .append(Integer.toString(hli.sync_result_no_of_copied)).append(" "); out.append(mContext.getString(R.string.msgs_sync_history_count_deleted)) .append(Integer.toString(hli.sync_result_no_of_deleted)).append(" "); out.append(mContext.getString(R.string.msgs_sync_history_count_ignored)) .append(Integer.toString(hli.sync_result_no_of_ignored)).append(" "); out.append("\n").append(hli.sync_error_text); } } if (out.length() > 0) cm.setText(out); if ((last_show_time + 1500) < System.currentTimeMillis()) { toast.show(); last_show_time = System.currentTimeMillis(); } mGp.syncHistoryAdapter.setAllItemChecked(false); mGp.syncHistoryAdapter.setShowCheckBox(false); mGp.syncHistoryAdapter.notifyDataSetChanged(); setHistoryContextButtonNormalMode(); } setContextButtonEnabled(mContextHistoryButtonHistiryCopyClipboard, true); } }); ContextButtonUtil.setButtonLabelListener(mContext, mContextHistoryButtonHistiryCopyClipboard, mContext.getString(R.string.msgs_hist_cont_label_copy)); mContextHistiryButtonSelectAll.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (enableMainUi) { setContextButtonEnabled(mContextHistiryButtonSelectAll, false); setHistoryItemSelectAll(); mGp.syncHistoryAdapter.setShowCheckBox(true); setHistoryContextButtonSelectMode(); setContextButtonEnabled(mContextHistiryButtonSelectAll, true); } } }); ContextButtonUtil.setButtonLabelListener(mContext, mContextHistiryButtonSelectAll, mContext.getString(R.string.msgs_hist_cont_label_select_all)); mContextHistiryButtonUnselectAll.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (enableMainUi) { setContextButtonEnabled(mContextHistiryButtonUnselectAll, false); setHistoryItemUnselectAll(); // mGp.syncHistoryAdapter.setShowCheckBox(false); // setHistoryContextButtonNotselected(); setContextButtonEnabled(mContextHistiryButtonUnselectAll, true); } } }); ContextButtonUtil.setButtonLabelListener(mContext, mContextHistiryButtonUnselectAll, mContext.getString(R.string.msgs_hist_cont_label_unselect_all)); }; private void setHistoryContextButtonSelectMode() { int sel_cnt = mGp.syncHistoryAdapter.getItemSelectedCount(); int tot_cnt = mGp.syncHistoryAdapter.getCount(); setActionBarSelectMode(sel_cnt, tot_cnt); mContextHistiryViewMoveTop.setVisibility(ImageButton.VISIBLE); mContextHistiryViewMoveBottom.setVisibility(ImageButton.VISIBLE); // if (sel_cnt==1) ll_show_log.setVisibility(ImageButton.VISIBLE); // else ll_show_log.setVisibility(ImageButton.GONE); if (sel_cnt > 0) { mContextHistiryViewDeleteHistory.setVisibility(ImageButton.VISIBLE); mContextHistiryViewHistoryCopyClipboard.setVisibility(ImageButton.VISIBLE); mContextHistiryViewUnselectAll.setVisibility(ImageButton.VISIBLE); } else { mContextHistiryViewDeleteHistory.setVisibility(ImageButton.GONE); mContextHistiryViewHistoryCopyClipboard.setVisibility(ImageButton.GONE); mContextHistiryViewUnselectAll.setVisibility(ImageButton.GONE); } if (tot_cnt != sel_cnt) mContextHistiryViewSelectAll.setVisibility(ImageButton.VISIBLE); else mContextHistiryViewSelectAll.setVisibility(ImageButton.GONE); }; private void setHistoryContextButtonNormalMode() { setActionBarNormalMode(); if (!mGp.syncHistoryAdapter.isEmptyAdapter()) { mContextHistiryViewMoveTop.setVisibility(ImageButton.VISIBLE); mContextHistiryViewMoveBottom.setVisibility(ImageButton.VISIBLE); mContextHistiryViewDeleteHistory.setVisibility(ImageButton.GONE); mContextHistiryViewHistoryCopyClipboard.setVisibility(ImageButton.GONE); if (isUiEnabled()) mContextHistiryViewSelectAll.setVisibility(ImageButton.VISIBLE); else mContextHistiryViewSelectAll.setVisibility(ImageButton.GONE); mContextHistiryViewUnselectAll.setVisibility(ImageButton.GONE); } else { mContextHistiryViewMoveTop.setVisibility(ImageButton.GONE); mContextHistiryViewMoveBottom.setVisibility(ImageButton.GONE); mContextHistiryViewDeleteHistory.setVisibility(ImageButton.GONE); mContextHistiryViewHistoryCopyClipboard.setVisibility(ImageButton.GONE); mContextHistiryViewSelectAll.setVisibility(ImageButton.GONE); mContextHistiryViewUnselectAll.setVisibility(ImageButton.GONE); } }; private void setHistoryItemUnselectAll() { mGp.syncHistoryAdapter.setAllItemChecked(false); // for (int i=0;i<mGp.syncHistoryAdapter.getCount();i++) mGp.syncHistoryAdapter.getItem(i).isChecked=false; // mGp.syncHistoryAdapter.setShowCheckBox(false); mGp.syncHistoryAdapter.notifyDataSetChanged(); setHistoryContextButtonSelectMode(); }; private void setHistoryItemSelectAll() { mGp.syncHistoryAdapter.setAllItemChecked(true); // for (int i=0;i<mGp.syncHistoryAdapter.getCount();i++) mGp.syncHistoryAdapter.getItem(i).isChecked=true; mGp.syncHistoryAdapter.setShowCheckBox(true); mGp.syncHistoryAdapter.notifyDataSetChanged(); setHistoryContextButtonSelectMode(); }; @SuppressWarnings("unused") private void setHistoryItemChecked(int pos, boolean p) { mGp.syncHistoryAdapter.getItem(pos).isChecked = p; }; private void confirmDeleteHistory() { String conf_list = ""; boolean del_all_history = false; int del_cnt = 0; String sep = ""; for (int i = 0; i < mGp.syncHistoryAdapter.getCount(); i++) { if (mGp.syncHistoryAdapter.getItem(i).isChecked) { del_cnt++; conf_list += sep + mGp.syncHistoryAdapter.getItem(i).sync_date + " " + mGp.syncHistoryAdapter.getItem(i).sync_time + " " + mGp.syncHistoryAdapter.getItem(i).sync_prof + " "; sep = "\n"; } } if (del_cnt == mGp.syncHistoryAdapter.getCount()) del_all_history = true; NotifyEvent ntfy = new NotifyEvent(this); ntfy.setListener(new NotifyEventListener() { @Override public void positiveResponse(Context c, Object[] o) { for (int i = mGp.syncHistoryAdapter.getCount() - 1; i >= 0; i--) { if (mGp.syncHistoryAdapter.getItem(i).isChecked) { String result_fp = mGp.syncHistoryAdapter.getItem(i).sync_result_file_path; if (!result_fp.equals("")) { File lf = new File(result_fp); if (lf.exists()) { lf.delete(); util.addDebugMsg(1, "I", "Sync history log file deleted, fp=" + result_fp); } } util.addDebugMsg(1, "I", "Sync history item deleted, item=" + mGp.syncHistoryAdapter.getItem(i).sync_prof); mGp.syncHistoryAdapter.remove(mGp.syncHistoryAdapter.getItem(i)); } } util.saveHistoryList(mGp.syncHistoryList); // mGp.syncHistoryAdapter.setSyncHistoryList(util.loadHistoryList()); mGp.syncHistoryAdapter.setShowCheckBox(false); mGp.syncHistoryAdapter.notifyDataSetChanged(); setHistoryContextButtonNormalMode(); } @Override public void negativeResponse(Context c, Object[] o) { } }); if (del_all_history) { // subtitle=getString(R.string.msgs_sync_history_del_conf_subtitle); commonDlg.showCommonDialog(true, "W", getString(R.string.msgs_sync_history_del_conf_all_history), "", ntfy); } else { // subtitle=getString(R.string.msgs_sync_history_del_conf_subtitle); commonDlg.showCommonDialog(true, "W", getString(R.string.msgs_sync_history_del_conf_selected_history), conf_list, ntfy); } }; // private void setMsglistLongClickListener() { // mGp.msgListView // .setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { // @Override // public boolean onItemLongClick(AdapterView<?> arg0, View arg1, // int arg2, long arg3) { // return true; // } // }); // }; private void setProfilelistItemClickListener() { mGp.syncTaskListView.setEnabled(true); mGp.syncTaskListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { if (isUiEnabled()) { mGp.syncTaskListView.setEnabled(false); SyncTaskItem item = mGp.syncTaskAdapter.getItem(position); if (!mGp.syncTaskAdapter.isShowCheckBox()) { editProfile(item.getSyncTaskName(), item.isSyncTaskAuto(), position); mUiHandler.postDelayed(new Runnable() { @Override public void run() { mGp.syncTaskListView.setEnabled(true); } }, 1000); } else { item.setChecked(!item.isChecked()); setProfileContextButtonSelectMode(); mGp.syncTaskListView.setEnabled(true); } mGp.syncTaskAdapter.notifyDataSetChanged(); } } }); NotifyEvent ntfy = new NotifyEvent(mContext); ntfy.setListener(new NotifyEventListener() { @Override public void positiveResponse(Context c, Object[] o) { if (!mGp.syncTaskAdapter.isShowCheckBox()) { // syncTaskListAdapter.setShowCheckBox(false); mGp.syncTaskAdapter.notifyDataSetChanged(); setProfileContextButtonNormalMode(); } else { setProfileContextButtonSelectMode(); } } @Override public void negativeResponse(Context c, Object[] o) { } }); mGp.syncTaskAdapter.setNotifyCheckBoxEventHandler(ntfy); }; private void setProfilelistLongClickListener() { mGp.syncTaskListView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(final AdapterView<?> list_view, final View item_view, int pos, long arg3) { if (mGp.syncTaskAdapter.isEmptyAdapter()) return true; if (!isUiEnabled()) return true; if (!mGp.syncTaskAdapter.getItem(pos).isChecked()) { if (SyncTaskUtility.isSyncTaskSelected(mGp.syncTaskAdapter)) { int down_sel_pos = -1, up_sel_pos = -1; int tot_cnt = mGp.syncTaskAdapter.getCount(); if (pos + 1 <= tot_cnt) { for (int i = pos + 1; i < tot_cnt; i++) { if (mGp.syncTaskAdapter.getItem(i).isChecked()) { up_sel_pos = i; break; } } } if (pos > 0) { for (int i = pos; i >= 0; i--) { if (mGp.syncTaskAdapter.getItem(i).isChecked()) { down_sel_pos = i; break; } } } // Log.v("","up="+up_sel_pos+", down="+down_sel_pos); if (up_sel_pos != -1 && down_sel_pos == -1) { for (int i = pos; i < up_sel_pos; i++) mGp.syncTaskAdapter.getItem(i).setChecked(true); } else if (up_sel_pos != -1 && down_sel_pos != -1) { for (int i = down_sel_pos + 1; i < up_sel_pos; i++) mGp.syncTaskAdapter.getItem(i).setChecked(true); } else if (up_sel_pos == -1 && down_sel_pos != -1) { for (int i = down_sel_pos + 1; i <= pos; i++) mGp.syncTaskAdapter.getItem(i).setChecked(true); } mGp.syncTaskAdapter.notifyDataSetChanged(); } else { mGp.syncTaskAdapter.setShowCheckBox(true); mGp.syncTaskAdapter.getItem(pos).setChecked(true); mGp.syncTaskAdapter.notifyDataSetChanged(); } setProfileContextButtonSelectMode(); } return true; } }); }; private ImageButton mContextProfileButtonActivete = null; private ImageButton mContextProfileButtonInactivete = null; private ImageButton mContextProfileButtonAddSync = null; private ImageButton mContextProfileButtonCopyProfile = null; private ImageButton mContextProfileButtonDeleteProfile = null; private ImageButton mContextProfileButtonRenameProfile = null; private ImageButton mContextProfileButtonMoveToUp = null; private ImageButton mContextProfileButtonMoveToDown = null; private ImageButton mContextProfileButtonSelectAll = null; private ImageButton mContextProfileButtonUnselectAll = null; // private Bitmap mContextProfileBitmapActive=null; // private Bitmap mContextProfileBitmapInactive=null; // private Bitmap mContextProfileBitmapAddLocal=null; // private Bitmap mContextProfileBitmapAddRemote=null; // private Bitmap mContextProfileBitmapAddSync=null; // private Bitmap mContextProfileBitmapStartWizard=null; // private Bitmap mContextProfileBitmapCopyProfile=null; // private Bitmap mContextProfileBitmapDeleteProfile=null; // private Bitmap mContextProfileBitmapRenameProfile=null; // private Bitmap mContextProfileBitmapSync=null; // private Bitmap mContextProfileBitmapSelectAll=null; // private Bitmap mContextProfileBitmapUnselectAll=null; private LinearLayout mContextProfileViewActivete = null; private LinearLayout mContextProfileViewInactivete = null; private LinearLayout mContextProfileViewAddSync = null; private LinearLayout mContextProfileViewCopyProfile = null; private LinearLayout mContextProfileViewDeleteProfile = null; private LinearLayout mContextProfileViewRenameProfile = null; private LinearLayout mContextProfileViewMoveToUp = null; private LinearLayout mContextProfileViewMoveToDown = null; private LinearLayout mContextProfileViewSelectAll = null; private LinearLayout mContextProfileViewUnselectAll = null; private ImageButton mContextHistoryButtonMoveTop = null; private ImageButton mContextHistoryButtonMoveBottom = null; private ImageButton mContextHistoryButtonDeleteHistory = null; private ImageButton mContextHistoryButtonHistiryCopyClipboard = null; private ImageButton mContextHistiryButtonSelectAll = null; private ImageButton mContextHistiryButtonUnselectAll = null; private LinearLayout mContextHistiryViewMoveTop = null; private LinearLayout mContextHistiryViewMoveBottom = null; private LinearLayout mContextHistiryViewDeleteHistory = null; private LinearLayout mContextHistiryViewHistoryCopyClipboard = null; private LinearLayout mContextHistiryViewSelectAll = null; private LinearLayout mContextHistiryViewUnselectAll = null; private ImageButton mContextMessageButtonMoveTop = null; private ImageButton mContextMessageButtonPinned = null; private ImageButton mContextMessageButtonMoveBottom = null; private ImageButton mContextMessageButtonClear = null; private LinearLayout mContextMessageViewMoveTop = null; private LinearLayout mContextMessageViewPinned = null; private LinearLayout mContextMessageViewMoveBottom = null; private LinearLayout mContextMessageViewClear = null; private void releaseImageResource() { releaseImageBtnRes(mContextProfileButtonActivete); releaseImageBtnRes(mContextProfileButtonInactivete); releaseImageBtnRes(mContextProfileButtonAddSync); releaseImageBtnRes(mContextProfileButtonCopyProfile); releaseImageBtnRes(mContextProfileButtonDeleteProfile); releaseImageBtnRes(mContextProfileButtonRenameProfile); releaseImageBtnRes(mContextProfileButtonMoveToUp); releaseImageBtnRes(mContextProfileButtonMoveToDown); releaseImageBtnRes(mContextProfileButtonSelectAll); releaseImageBtnRes(mContextProfileButtonUnselectAll); releaseImageBtnRes(mContextHistoryButtonMoveTop); releaseImageBtnRes(mContextHistoryButtonMoveBottom); releaseImageBtnRes(mContextHistoryButtonDeleteHistory); releaseImageBtnRes(mContextHistoryButtonHistiryCopyClipboard); releaseImageBtnRes(mContextHistiryButtonSelectAll); releaseImageBtnRes(mContextHistiryButtonUnselectAll); releaseImageBtnRes(mContextMessageButtonMoveTop); releaseImageBtnRes(mContextMessageButtonPinned); releaseImageBtnRes(mContextMessageButtonMoveBottom); releaseImageBtnRes(mContextMessageButtonClear); mGp.syncTaskListView.setAdapter(null); mGp.syncHistoryListView.setAdapter(null); }; private void releaseImageBtnRes(ImageButton ib) { // ((BitmapDrawable) ib.getDrawable()).getBitmap().recycle(); ib.setImageDrawable(null); // ib.setBackground(null); ib.setBackgroundDrawable(null); ib.setImageBitmap(null); }; private void createContextView() { // if (mContextProfileBitmapActive==null) { // mContextProfileBitmapActive=BitmapFactory.decodeResource(getResources(), R.drawable.menu_active); // mContextProfileBitmapInactive=BitmapFactory.decodeResource(getResources(), R.drawable.menu_inactive); // mContextProfileBitmapAddLocal=BitmapFactory.decodeResource(getResources(), R.drawable.add_local); // mContextProfileBitmapAddRemote=BitmapFactory.decodeResource(getResources(), R.drawable.add_remote); // mContextProfileBitmapAddSync=BitmapFactory.decodeResource(getResources(), R.drawable.add_sync); // mContextProfileBitmapStartWizard=BitmapFactory.decodeResource(getResources(), R.drawable.ic_64_wizard); // mContextProfileBitmapCopyProfile=BitmapFactory.decodeResource(getResources(), R.drawable.menu_copy); // mContextProfileBitmapDeleteProfile=BitmapFactory.decodeResource(getResources(), R.drawable.menu_trash); // mContextProfileBitmapRenameProfile=BitmapFactory.decodeResource(getResources(), R.drawable.menu_rename); // mContextProfileBitmapSync=BitmapFactory.decodeResource(getResources(), R.drawable.ic_32_sync); // mContextProfileBitmapSelectAll=BitmapFactory.decodeResource(getResources(), R.drawable.select_all); // mContextProfileBitmapUnselectAll=BitmapFactory.decodeResource(getResources(), R.drawable.unselect_all); // } mContextProfileButtonActivete = (ImageButton) mProfileView.findViewById(R.id.context_button_activate); mContextProfileButtonInactivete = (ImageButton) mProfileView.findViewById(R.id.context_button_inactivate); mContextProfileButtonAddSync = (ImageButton) mProfileView.findViewById(R.id.context_button_add_sync); mContextProfileButtonCopyProfile = (ImageButton) mProfileView.findViewById(R.id.context_button_copy); mContextProfileButtonDeleteProfile = (ImageButton) mProfileView.findViewById(R.id.context_button_delete); mContextProfileButtonRenameProfile = (ImageButton) mProfileView.findViewById(R.id.context_button_rename); mContextProfileButtonMoveToUp = (ImageButton) mProfileView.findViewById(R.id.context_button_up_arrow); mContextProfileButtonMoveToDown = (ImageButton) mProfileView.findViewById(R.id.context_button_down_arrow); mContextProfileButtonSelectAll = (ImageButton) mProfileView.findViewById(R.id.context_button_select_all); mContextProfileButtonUnselectAll = (ImageButton) mProfileView .findViewById(R.id.context_button_unselect_all); // mContextProfileButtonActivete.setImageBitmap(mContextProfileBitmapActive); // mContextProfileButtonInactivete.setImageBitmap(mContextProfileBitmapInactive); // mContextProfileButtonAddLocal.setImageBitmap(mContextProfileBitmapAddLocal); // mContextProfileButtonAddRemote.setImageBitmap(mContextProfileBitmapAddRemote); // mContextProfileButtonAddSync.setImageBitmap(mContextProfileBitmapAddSync); // mContextProfileButtonStartWizard.setImageBitmap(mContextProfileBitmapStartWizard); // mContextProfileButtonCopyProfile.setImageBitmap(mContextProfileBitmapCopyProfile); // mContextProfileButtonDeleteProfile.setImageBitmap(mContextProfileBitmapDeleteProfile); // mContextProfileButtonRenameProfile.setImageBitmap(mContextProfileBitmapRenameProfile); // mContextProfileButtonSync.setImageBitmap(mContextProfileBitmapSync); // mContextProfileButtonSelectAll.setImageBitmap(mContextProfileBitmapSelectAll); // mContextProfileButtonUnselectAll.setImageBitmap(mContextProfileBitmapUnselectAll); mContextProfileViewActivete = (LinearLayout) mProfileView.findViewById(R.id.context_button_activate_view); mContextProfileViewInactivete = (LinearLayout) mProfileView .findViewById(R.id.context_button_inactivate_view); mContextProfileViewAddSync = (LinearLayout) mProfileView.findViewById(R.id.context_button_add_sync_view); mContextProfileViewCopyProfile = (LinearLayout) mProfileView.findViewById(R.id.context_button_copy_view); mContextProfileViewDeleteProfile = (LinearLayout) mProfileView .findViewById(R.id.context_button_delete_view); mContextProfileViewRenameProfile = (LinearLayout) mProfileView .findViewById(R.id.context_button_rename_view); mContextProfileViewMoveToUp = (LinearLayout) mProfileView.findViewById(R.id.context_button_up_arrow_view); mContextProfileViewMoveToDown = (LinearLayout) mProfileView .findViewById(R.id.context_button_down_arrow_view); mContextProfileViewSelectAll = (LinearLayout) mProfileView .findViewById(R.id.context_button_select_all_view); mContextProfileViewUnselectAll = (LinearLayout) mProfileView .findViewById(R.id.context_button_unselect_all_view); mContextHistoryButtonMoveTop = (ImageButton) mHistoryView.findViewById(R.id.context_button_move_to_top); mContextHistoryButtonMoveBottom = (ImageButton) mHistoryView .findViewById(R.id.context_button_move_to_bottom); mContextHistoryButtonDeleteHistory = (ImageButton) mHistoryView.findViewById(R.id.context_button_delete); mContextHistoryButtonHistiryCopyClipboard = (ImageButton) mHistoryView .findViewById(R.id.context_button_copy_to_clipboard); mContextHistiryButtonSelectAll = (ImageButton) mHistoryView.findViewById(R.id.context_button_select_all); mContextHistiryButtonUnselectAll = (ImageButton) mHistoryView .findViewById(R.id.context_button_unselect_all); mContextHistiryViewMoveTop = (LinearLayout) mHistoryView.findViewById(R.id.context_button_move_to_top_view); mContextHistiryViewMoveBottom = (LinearLayout) mHistoryView .findViewById(R.id.context_button_move_to_bottom_view); mContextHistiryViewDeleteHistory = (LinearLayout) mHistoryView .findViewById(R.id.context_button_delete_view); mContextHistiryViewHistoryCopyClipboard = (LinearLayout) mHistoryView .findViewById(R.id.context_button_copy_to_clipboard_view); mContextHistiryViewSelectAll = (LinearLayout) mHistoryView .findViewById(R.id.context_button_select_all_view); mContextHistiryViewUnselectAll = (LinearLayout) mHistoryView .findViewById(R.id.context_button_unselect_all_view); mContextMessageButtonPinned = (ImageButton) mMessageView.findViewById(R.id.context_button_pinned); mContextMessageButtonMoveTop = (ImageButton) mMessageView.findViewById(R.id.context_button_move_to_top); mContextMessageButtonMoveBottom = (ImageButton) mMessageView .findViewById(R.id.context_button_move_to_bottom); mContextMessageButtonClear = (ImageButton) mMessageView.findViewById(R.id.context_button_clear); mContextMessageViewPinned = (LinearLayout) mMessageView.findViewById(R.id.context_button_pinned_view); mContextMessageViewMoveTop = (LinearLayout) mMessageView.findViewById(R.id.context_button_move_to_top_view); mContextMessageViewMoveBottom = (LinearLayout) mMessageView .findViewById(R.id.context_button_move_to_bottom_view); mContextMessageViewClear = (LinearLayout) mMessageView.findViewById(R.id.context_button_clear_view); }; private void setContextButtonEnabled(final ImageButton btn, boolean enabled) { if (enabled) { btn.postDelayed(new Runnable() { @Override public void run() { btn.setEnabled(true); } }, 1000); } else { btn.setEnabled(false); } }; private void setProfileContextButtonListener() { final NotifyEvent ntfy = new NotifyEvent(mContext); ntfy.setListener(new NotifyEventListener() { @Override public void positiveResponse(Context c, Object[] o) { if (mGp.syncTaskAdapter.isShowCheckBox()) setProfileContextButtonSelectMode(); else setProfileContextButtonNormalMode(); checkSafExternalSdcardTreeUri(null); } @Override public void negativeResponse(Context c, Object[] o) { checkSafExternalSdcardTreeUri(null); } }); mContextProfileButtonActivete.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (enableMainUi) confirmActivate(mGp.syncTaskAdapter, ntfy); } }); ContextButtonUtil.setButtonLabelListener(mContext, mContextProfileButtonActivete, mContext.getString(R.string.msgs_prof_cont_label_activate)); mContextProfileButtonInactivete.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (enableMainUi) confirmInactivate(mGp.syncTaskAdapter, ntfy); } }); ContextButtonUtil.setButtonLabelListener(mContext, mContextProfileButtonInactivete, mContext.getString(R.string.msgs_prof_cont_label_inactivate)); mContextProfileButtonAddSync.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (enableMainUi) { setContextButtonEnabled(mContextProfileButtonAddSync, false); SyncTaskItem pfli = new SyncTaskItem(); pfli.setSyncTaskAuto(true); SyncTaskEditor pmsp = SyncTaskEditor.newInstance(); pmsp.showDialog(getSupportFragmentManager(), pmsp, "ADD", pfli, profUtil, util, commonDlg, ntfy); setContextButtonEnabled(mContextProfileButtonAddSync, true); } } }); ContextButtonUtil.setButtonLabelListener(mContext, mContextProfileButtonAddSync, mContext.getString(R.string.msgs_prof_cont_label_add_sync)); mContextProfileButtonCopyProfile.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (enableMainUi) { setContextButtonEnabled(mContextProfileButtonCopyProfile, false); for (int i = 0; i < mGp.syncTaskAdapter.getCount(); i++) { SyncTaskItem item = mGp.syncTaskAdapter.getItem(i); if (item.isChecked()) { profUtil.copySyncTask(item, ntfy); break; } } setContextButtonEnabled(mContextProfileButtonCopyProfile, true); } } }); ContextButtonUtil.setButtonLabelListener(mContext, mContextProfileButtonCopyProfile, mContext.getString(R.string.msgs_prof_cont_label_copy)); mContextProfileButtonDeleteProfile.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (enableMainUi) { setContextButtonEnabled(mContextProfileButtonDeleteProfile, false); profUtil.deleteSyncTask(ntfy); setContextButtonEnabled(mContextProfileButtonDeleteProfile, true); } } }); ContextButtonUtil.setButtonLabelListener(mContext, mContextProfileButtonDeleteProfile, mContext.getString(R.string.msgs_prof_cont_label_delete)); mContextProfileButtonRenameProfile.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (enableMainUi) { setContextButtonEnabled(mContextProfileButtonRenameProfile, false); for (int i = 0; i < mGp.syncTaskAdapter.getCount(); i++) { SyncTaskItem item = mGp.syncTaskAdapter.getItem(i); if (item.isChecked()) { profUtil.renameProfile(item, ntfy); break; } } setContextButtonEnabled(mContextProfileButtonRenameProfile, true); } } }); ContextButtonUtil.setButtonLabelListener(mContext, mContextProfileButtonRenameProfile, mContext.getString(R.string.msgs_prof_cont_label_rename)); mContextProfileButtonMoveToUp.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (enableMainUi) { for (int i = 0; i < mGp.syncTaskAdapter.getCount(); i++) { SyncTaskItem item = mGp.syncTaskAdapter.getItem(i); if (item.isChecked()) { int c_pos = item.getSyncTaskPosition(); if (c_pos > 0) { for (int j = 0; j < mGp.syncTaskAdapter.getCount(); j++) { if (mGp.syncTaskAdapter.getItem(j).getSyncTaskPosition() == (c_pos - 1)) { mGp.syncTaskAdapter.getItem(j).setSyncTaskPosition(c_pos); } } item.setSyncTaskPosition(c_pos - 1); mGp.syncTaskAdapter.sort(); SyncTaskUtility.saveSyncTaskListToFile(mGp, mContext, util, false, "", "", mGp.syncTaskList, false); mGp.syncTaskAdapter.notifyDataSetChanged(); if (item.getSyncTaskPosition() == 0) { mContextProfileViewMoveToUp.setVisibility(ImageButton.GONE); mContextProfileViewMoveToDown.setVisibility(ImageButton.VISIBLE); } if (item.getSyncTaskPosition() == (mGp.syncTaskAdapter.getCount() - 1)) { mContextProfileViewMoveToUp.setVisibility(ImageButton.VISIBLE); mContextProfileViewMoveToDown.setVisibility(ImageButton.GONE); } } break; } } } } }); ContextButtonUtil.setButtonLabelListener(mContext, mContextProfileButtonMoveToUp, mContext.getString(R.string.msgs_prof_cont_label_up)); mContextProfileButtonMoveToDown.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (enableMainUi) { for (int i = 0; i < mGp.syncTaskAdapter.getCount(); i++) { SyncTaskItem item = mGp.syncTaskAdapter.getItem(i); if (item.isChecked()) { int c_pos = item.getSyncTaskPosition(); if (item.getSyncTaskPosition() < (mGp.syncTaskAdapter.getCount() - 1)) { for (int j = 0; j < mGp.syncTaskAdapter.getCount(); j++) { if (mGp.syncTaskAdapter.getItem(j).getSyncTaskPosition() == (c_pos + 1)) { mGp.syncTaskAdapter.getItem(j).setSyncTaskPosition(c_pos); } } item.setSyncTaskPosition(c_pos + 1); mGp.syncTaskAdapter.sort(); SyncTaskUtility.saveSyncTaskListToFile(mGp, mContext, util, false, "", "", mGp.syncTaskList, false); mGp.syncTaskAdapter.notifyDataSetChanged(); if (item.getSyncTaskPosition() == 0) { mContextProfileViewMoveToUp.setVisibility(ImageButton.GONE); mContextProfileViewMoveToDown.setVisibility(ImageButton.VISIBLE); } if (item.getSyncTaskPosition() == (mGp.syncTaskAdapter.getCount() - 1)) { mContextProfileViewMoveToUp.setVisibility(ImageButton.VISIBLE); mContextProfileViewMoveToDown.setVisibility(ImageButton.GONE); } } break; } } } } }); ContextButtonUtil.setButtonLabelListener(mContext, mContextProfileButtonMoveToDown, mContext.getString(R.string.msgs_prof_cont_label_down)); // mContextProfileButtonSync.setOnClickListener(new OnClickListener(){ // @Override // public void onClick(View v) { // if (enableMainUi) { // setContextButtonEnabled(mContextProfileButtonSync,false); // if (SyncTaskUtility.getProfileSelectedItemCount(mGp.syncTaskListAdapter)>0) { // syncSelectedProfile(); // Toast.makeText(mContext, // mContext.getString(R.string.msgs_sync_selected_profiles), // Toast.LENGTH_LONG) // .show(); // } else { // syncActiveProfile(); // Toast.makeText(mContext, // mContext.getString(R.string.msgs_sync_all_active_profiles), // Toast.LENGTH_LONG) // .show(); // } // SyncTaskUtility.setAllProfileToUnchecked(true, mGp.syncTaskListAdapter); // setProfileContextButtonNormalMode(); // setContextButtonEnabled(mContextProfileButtonSync,true); // } // } // }); // ContextButtonUtil.setButtonLabelListener(mContext, mContextProfileButtonSync,mContext.getString(R.string.msgs_prof_cont_label_sync)); // mContextProfileButtonSelectAll.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (enableMainUi) { setContextButtonEnabled(mContextProfileButtonSelectAll, false); for (int i = 0; i < mGp.syncTaskAdapter.getCount(); i++) { SyncTaskUtility.setSyncTaskToChecked(true, mGp.syncTaskAdapter, i); } mGp.syncTaskAdapter.notifyDataSetChanged(); mGp.syncTaskAdapter.setShowCheckBox(true); setProfileContextButtonSelectMode(); setContextButtonEnabled(mContextProfileButtonSelectAll, true); } } }); ContextButtonUtil.setButtonLabelListener(mContext, mContextProfileButtonSelectAll, mContext.getString(R.string.msgs_prof_cont_label_select_all)); mContextProfileButtonUnselectAll.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (enableMainUi) { setContextButtonEnabled(mContextProfileButtonUnselectAll, false); SyncTaskUtility.setAllSyncTaskToUnchecked(false, mGp.syncTaskAdapter); // for (int i=0;i<syncTaskListAdapter.getCount();i++) { // ProfileUtility.setProfileToChecked(false, syncTaskListAdapter, i); // } mGp.syncTaskAdapter.notifyDataSetChanged(); setProfileContextButtonSelectMode(); setContextButtonEnabled(mContextProfileButtonUnselectAll, true); } } }); ContextButtonUtil.setButtonLabelListener(mContext, mContextProfileButtonUnselectAll, mContext.getString(R.string.msgs_prof_cont_label_unselect_all)); }; private void confirmActivate(AdapterSyncTask pa, final NotifyEvent p_ntfy) { NotifyEvent ntfy = new NotifyEvent(mContext); ntfy.setListener(new NotifyEventListener() { @Override public void positiveResponse(Context c, Object[] o) { profUtil.setProfileToActive(mGp); SyncTaskUtility.setAllSyncTaskToUnchecked(true, mGp.syncTaskAdapter); p_ntfy.notifyToListener(true, null); } @Override public void negativeResponse(Context c, Object[] o) { } }); String msg = ""; String sep = ""; for (int i = 0; i < pa.getCount(); i++) { if (pa.getItem(i).isChecked() && !pa.getItem(i).isSyncTaskAuto()) { msg += sep + pa.getItem(i).getSyncTaskName(); sep = "\n"; } } // msg+="\n"; commonDlg.showCommonDialog(true, "W", mContext.getString(R.string.msgs_prof_cont_to_activate_profile), msg, ntfy); }; private void confirmInactivate(AdapterSyncTask pa, final NotifyEvent p_ntfy) { NotifyEvent ntfy = new NotifyEvent(mContext); ntfy.setListener(new NotifyEventListener() { @Override public void positiveResponse(Context c, Object[] o) { profUtil.setProfileToInactive(); SyncTaskUtility.setAllSyncTaskToUnchecked(true, mGp.syncTaskAdapter); p_ntfy.notifyToListener(true, null); } @Override public void negativeResponse(Context c, Object[] o) { } }); String msg = ""; String sep = ""; for (int i = 0; i < pa.getCount(); i++) { if (pa.getItem(i).isChecked() && pa.getItem(i).isSyncTaskAuto()) { msg += sep + pa.getItem(i).getSyncTaskName(); sep = "\n"; } } // msg+="\n"; commonDlg.showCommonDialog(true, "W", mContext.getString(R.string.msgs_prof_cont_to_inactivate_profile), msg, ntfy); }; private void setProfileContextButtonSelectMode() { int sel_cnt = SyncTaskUtility.getSyncTaskSelectedItemCount(mGp.syncTaskAdapter); int tot_cnt = mGp.syncTaskAdapter.getCount(); setActionBarSelectMode(sel_cnt, tot_cnt); boolean any_selected = SyncTaskUtility.isSyncTaskSelected(mGp.syncTaskAdapter); boolean act_prof_selected = false, inact_prof_selected = false; if (any_selected) { for (int i = 0; i < tot_cnt; i++) { if (mGp.syncTaskAdapter.getItem(i).isChecked()) { if (mGp.syncTaskAdapter.getItem(i).isSyncTaskAuto()) act_prof_selected = true; else inact_prof_selected = true; if (act_prof_selected && inact_prof_selected) break; } } } if (inact_prof_selected) { if (any_selected) mContextProfileViewActivete.setVisibility(ImageButton.VISIBLE); else mContextProfileViewActivete.setVisibility(ImageButton.GONE); } else mContextProfileViewActivete.setVisibility(ImageButton.GONE); if (act_prof_selected) { if (any_selected) mContextProfileViewInactivete.setVisibility(ImageButton.VISIBLE); else mContextProfileViewInactivete.setVisibility(ImageButton.GONE); } else mContextProfileViewInactivete.setVisibility(ImageButton.GONE); mContextProfileViewAddSync.setVisibility(ImageButton.GONE); if (sel_cnt == 1) mContextProfileViewCopyProfile.setVisibility(ImageButton.VISIBLE); else mContextProfileViewCopyProfile.setVisibility(ImageButton.GONE); if (any_selected) mContextProfileViewDeleteProfile.setVisibility(ImageButton.VISIBLE); else mContextProfileViewDeleteProfile.setVisibility(ImageButton.GONE); if (sel_cnt == 1) mContextProfileViewRenameProfile.setVisibility(ImageButton.VISIBLE); else mContextProfileViewRenameProfile.setVisibility(ImageButton.GONE); if (sel_cnt == 1) mContextProfileViewMoveToUp.setVisibility(ImageButton.VISIBLE); else mContextProfileViewMoveToUp.setVisibility(ImageButton.GONE); if (sel_cnt == 1) mContextProfileViewMoveToDown.setVisibility(ImageButton.VISIBLE); else mContextProfileViewMoveToDown.setVisibility(ImageButton.GONE); if (sel_cnt == 1) { for (int i = 0; i < tot_cnt; i++) { if (mGp.syncTaskAdapter.getItem(i).isChecked()) { if (i == 0) mContextProfileViewMoveToUp.setVisibility(ImageButton.GONE); if (i == (tot_cnt - 1)) mContextProfileViewMoveToDown.setVisibility(ImageButton.GONE); } } } if (tot_cnt != sel_cnt) mContextProfileViewSelectAll.setVisibility(ImageButton.VISIBLE); else mContextProfileViewSelectAll.setVisibility(ImageButton.GONE); if (any_selected) mContextProfileViewUnselectAll.setVisibility(ImageButton.VISIBLE); else mContextProfileViewUnselectAll.setVisibility(ImageButton.GONE); refreshOptionMenu(); }; private void setProfileContextButtonHide() { mActionBar.setIcon(R.drawable.smbsync); mActionBar.setHomeButtonEnabled(false); mActionBar.setTitle(R.string.app_name); mGp.syncTaskAdapter.setAllItemChecked(false); mGp.syncTaskAdapter.setShowCheckBox(false); mGp.syncTaskAdapter.notifyDataSetChanged(); mContextProfileViewActivete.setVisibility(ImageButton.GONE); mContextProfileViewInactivete.setVisibility(ImageButton.GONE); mContextProfileViewAddSync.setVisibility(ImageButton.GONE); mContextProfileViewCopyProfile.setVisibility(ImageButton.GONE); mContextProfileViewDeleteProfile.setVisibility(ImageButton.GONE); mContextProfileViewRenameProfile.setVisibility(ImageButton.GONE); mContextProfileViewMoveToUp.setVisibility(ImageButton.GONE); mContextProfileViewMoveToDown.setVisibility(ImageButton.GONE); mContextProfileViewSelectAll.setVisibility(ImageButton.GONE); mContextProfileViewUnselectAll.setVisibility(ImageButton.GONE); }; private void setActionBarSelectMode(int sel_cnt, int tot_cnt) { ActionBar actionBar = getSupportActionBar(); actionBar.setHomeButtonEnabled(true); actionBar.setDisplayHomeAsUpEnabled(true); String sel_txt = "" + sel_cnt + "/" + tot_cnt; actionBar.setTitle(sel_txt); }; private void setActionBarNormalMode() { ActionBar actionBar = getSupportActionBar(); actionBar.setTitle(R.string.app_name); actionBar.setHomeButtonEnabled(false); actionBar.setDisplayHomeAsUpEnabled(false); }; private void setProfileContextButtonNormalMode() { setActionBarNormalMode(); mGp.syncTaskAdapter.setAllItemChecked(false); mGp.syncTaskAdapter.setShowCheckBox(false); mGp.syncTaskAdapter.notifyDataSetChanged(); mContextProfileViewActivete.setVisibility(ImageButton.GONE); mContextProfileViewInactivete.setVisibility(ImageButton.GONE); if (isUiEnabled()) mContextProfileViewAddSync.setVisibility(ImageButton.VISIBLE); else mContextProfileViewAddSync.setVisibility(ImageButton.GONE); mContextProfileViewCopyProfile.setVisibility(ImageButton.GONE); mContextProfileViewDeleteProfile.setVisibility(ImageButton.GONE); mContextProfileViewRenameProfile.setVisibility(ImageButton.GONE); mContextProfileViewMoveToUp.setVisibility(ImageButton.GONE); mContextProfileViewMoveToDown.setVisibility(ImageButton.GONE); if (isUiEnabled()) { if (!mGp.syncTaskAdapter.isEmptyAdapter()) mContextProfileViewSelectAll.setVisibility(ImageButton.VISIBLE); else mContextProfileViewSelectAll.setVisibility(ImageButton.GONE); } else { mContextProfileViewSelectAll.setVisibility(ImageButton.GONE); } mContextProfileViewUnselectAll.setVisibility(ImageButton.GONE); refreshOptionMenu(); }; @SuppressLint("ShowToast") private void setMessageContextButtonListener() { final Toast toast_active = Toast.makeText(mContext, mContext.getString(R.string.msgs_log_activate_pinned), Toast.LENGTH_SHORT); final Toast toast_inactive = Toast.makeText(mContext, mContext.getString(R.string.msgs_log_inactivate_pinned), Toast.LENGTH_SHORT); mContextMessageButtonPinned.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { setContextButtonEnabled(mContextMessageButtonPinned, false); mGp.freezeMessageViewScroll = !mGp.freezeMessageViewScroll; if (mGp.freezeMessageViewScroll) { mContextMessageButtonPinned.setImageResource(R.drawable.context_button_pinned_active); toast_active.show(); ContextButtonUtil.setButtonLabelListener(mContext, mContextMessageButtonPinned, mContext.getString(R.string.msgs_msg_cont_label_pinned_active)); } else { mContextMessageButtonPinned.setImageResource(R.drawable.context_button_pinned_inactive); mGp.msgListView.setSelection(mGp.msgListView.getCount() - 1); toast_inactive.show(); ContextButtonUtil.setButtonLabelListener(mContext, mContextMessageButtonPinned, mContext.getString(R.string.msgs_msg_cont_label_pinned_inactive)); } setContextButtonEnabled(mContextMessageButtonPinned, true); } }); ContextButtonUtil.setButtonLabelListener(mContext, mContextMessageButtonPinned, mContext.getString(R.string.msgs_msg_cont_label_pinned_inactive)); mContextMessageButtonMoveTop.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { setContextButtonEnabled(mContextMessageButtonMoveTop, false); mGp.msgListView.setSelection(0); setContextButtonEnabled(mContextMessageButtonMoveTop, true); } }); ContextButtonUtil.setButtonLabelListener(mContext, mContextMessageButtonMoveTop, mContext.getString(R.string.msgs_msg_cont_label_move_top)); mContextMessageButtonMoveBottom.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { setContextButtonEnabled(mContextMessageButtonMoveBottom, false); mGp.msgListView.setSelection(mGp.msgListView.getCount() - 1); setContextButtonEnabled(mContextMessageButtonMoveBottom, true); } }); ContextButtonUtil.setButtonLabelListener(mContext, mContextMessageButtonMoveBottom, mContext.getString(R.string.msgs_msg_cont_label_move_bottom)); mContextMessageButtonClear.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { NotifyEvent ntfy = new NotifyEvent(mContext); ntfy.setListener(new NotifyEventListener() { @Override public void positiveResponse(Context c, Object[] o) { mGp.msgListView.setSelection(0); mGp.msgListAdapter.clear(); util.addLogMsg("W", getString(R.string.msgs_log_msg_cleared)); } @Override public void negativeResponse(Context c, Object[] o) { } }); commonDlg.showCommonDialog(true, "W", mContext.getString(R.string.msgs_log_confirm_clear_all_msg), "", ntfy); } }); ContextButtonUtil.setButtonLabelListener(mContext, mContextMessageButtonClear, mContext.getString(R.string.msgs_msg_cont_label_clear)); }; private void setMessageContextButtonNormalMode() { mContextMessageViewPinned.setVisibility(LinearLayout.VISIBLE); if (mGp.freezeMessageViewScroll) { mContextMessageButtonPinned.setImageResource(R.drawable.context_button_pinned_active); } else { mContextMessageButtonPinned.setImageResource(R.drawable.context_button_pinned_inactive); } mContextMessageViewMoveTop.setVisibility(LinearLayout.VISIBLE); mContextMessageViewMoveBottom.setVisibility(LinearLayout.VISIBLE); mContextMessageViewClear.setVisibility(LinearLayout.VISIBLE); }; private void editProfile(String prof_name, boolean prof_act, int prof_num) { SyncTaskItem item = mGp.syncTaskAdapter.getItem(prof_num); NotifyEvent ntfy = new NotifyEvent(mContext); ntfy.setListener(new NotifyEventListener() { @Override public void positiveResponse(Context c, Object[] o) { checkSafExternalSdcardTreeUri(null); } @Override public void negativeResponse(Context c, Object[] o) { checkSafExternalSdcardTreeUri(null); } }); SyncTaskEditor pmp = SyncTaskEditor.newInstance(); pmp.showDialog(getSupportFragmentManager(), pmp, "EDIT", item, profUtil, util, commonDlg, ntfy); }; private void syncSelectedProfile() { final ArrayList<SyncTaskItem> t_list = new ArrayList<SyncTaskItem>(); SyncTaskItem item; String sync_list_tmp = ""; String sep = ""; for (int i = 0; i < mGp.syncTaskAdapter.getCount(); i++) { item = mGp.syncTaskAdapter.getItem(i); if (item.isChecked()) { t_list.add(item); sync_list_tmp += sep + item.getSyncTaskName(); sep = ","; } } final String sync_list = sync_list_tmp; ; if (t_list.isEmpty()) { util.addLogMsg("E", mContext.getString(R.string.msgs_sync_select_prof_no_active_profile)); commonDlg.showCommonDialog(false, "E", mContext.getString(R.string.msgs_sync_select_prof_no_active_profile), "", null); } else { NotifyEvent ntfy = new NotifyEvent(mContext); ntfy.setListener(new NotifyEventListener() { @Override public void positiveResponse(Context c, Object[] o) { util.addLogMsg("I", mContext.getString(R.string.msgs_sync_selected_profiles)); util.addLogMsg("I", mContext.getString(R.string.msgs_sync_prof_name_list) + " " + sync_list); Toast.makeText(mContext, mContext.getString(R.string.msgs_sync_selected_profiles), Toast.LENGTH_SHORT).show(); startSyncTask(t_list); } @Override public void negativeResponse(Context c, Object[] o) { } }); confirmUseAppSpecificDir(t_list, ntfy); } }; private void confirmUseAppSpecificDir(final ArrayList<SyncTaskItem> alp, final NotifyEvent p_ntfy) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mContext); if (!prefs.getBoolean(getString(R.string.settings_suppress_warning_app_specific_dir), false)) { boolean app_specific_used = false; String prof_list = "", sep = ""; for (int i = 0; i < alp.size(); i++) { if (alp.get(i).getTargetFolderType().equals(SyncTaskItem.SYNC_FOLDER_TYPE_INTERNAL) || alp.get(i).getTargetFolderType().equals(SyncTaskItem.SYNC_FOLDER_TYPE_SDCARD)) { if (alp.get(i).getTargetDirectoryName().startsWith(APP_SPECIFIC_DIRECTORY)) { app_specific_used = true; prof_list += sep + alp.get(i).getSyncTaskName(); sep = ","; } } } if (app_specific_used) { final Dialog dialog = new Dialog(mActivity);//, android.R.style.Theme_Black); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setContentView(R.layout.confirm_app_specific_dir_dlg); final LinearLayout title_view = (LinearLayout) dialog .findViewById(R.id.confirm_app_specific_dlg_title_view); final TextView title = (TextView) dialog.findViewById(R.id.confirm_app_specific_dlg_title); title_view.setBackgroundColor(mGp.themeColorList.dialog_title_background_color); title.setText(mContext.getString(R.string.msgs_local_mount_point_app_specific_dir_used_title)); title.setTextColor(mGp.themeColorList.text_color_warning); ((TextView) dialog.findViewById(R.id.confirm_app_specific_dlg_msg)) .setText(mContext.getString(R.string.msgs_local_mount_point_app_specific_dir_used_msg) + "\n\n" + prof_list + "\n"); final Button btnOk = (Button) dialog.findViewById(R.id.confirm_app_specific_dlg_ok); final Button btnCancel = (Button) dialog.findViewById(R.id.confirm_app_specific_dlg_cancel); final CheckedTextView ctvSuppr = (CheckedTextView) dialog .findViewById(R.id.confirm_app_specific_dlg_ctv_suppress); CommonUtilities.setCheckedTextView(ctvSuppr); CommonDialog.setDlgBoxSizeCompact(dialog); ctvSuppr.setChecked(false); // OK? btnOk.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { dialog.dismiss(); if (ctvSuppr.isChecked()) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mContext); prefs.edit().putBoolean(getString(R.string.settings_suppress_warning_app_specific_dir), true).commit(); } p_ntfy.notifyToListener(true, null); } }); // Cancel? btnCancel.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { dialog.dismiss(); p_ntfy.notifyToListener(false, null); } }); // Cancel? dialog.setOnCancelListener(new Dialog.OnCancelListener() { @Override public void onCancel(DialogInterface arg0) { btnOk.performClick(); } }); // dialog.setOnKeyListener(new DialogOnKeyListener(mContext)); // dialog.setCancelable(false); dialog.show(); } else { p_ntfy.notifyToListener(true, null); } } else { p_ntfy.notifyToListener(true, null); } } private void syncActiveProfile() { final ArrayList<SyncTaskItem> t_list = new ArrayList<SyncTaskItem>(); String sync_list_tmp = "", sep = ""; for (int i = 0; i < mGp.syncTaskAdapter.getCount(); i++) { SyncTaskItem item = mGp.syncTaskAdapter.getItem(i); if (item.isSyncTaskAuto() && !item.isSyncTestMode()) { t_list.add(item); sync_list_tmp += sep + item.getSyncTaskName(); sep = ","; } } if (t_list.isEmpty()) { util.addLogMsg("E", mContext.getString(R.string.msgs_active_sync_prof_not_found)); commonDlg.showCommonDialog(false, "E", mContext.getString(R.string.msgs_active_sync_prof_not_found), "", null); } else { final String sync_list = sync_list_tmp; NotifyEvent ntfy = new NotifyEvent(mContext); ntfy.setListener(new NotifyEventListener() { @Override public void positiveResponse(Context c, Object[] o) { util.addLogMsg("I", mContext.getString(R.string.msgs_sync_all_active_profiles)); util.addLogMsg("I", mContext.getString(R.string.msgs_sync_prof_name_list) + sync_list); // tabHost.setCurrentTabByTag(TAB_TAG_MSG); Toast.makeText(mContext, mContext.getString(R.string.msgs_sync_all_active_profiles), Toast.LENGTH_SHORT).show(); startSyncTask(t_list); } @Override public void negativeResponse(Context c, Object[] o) { } }); confirmUseAppSpecificDir(t_list, ntfy); } }; private void setUiEnabled() { util.addDebugMsg(1, "I", "setUiEnabled entered"); enableMainUi = true; if (!mGp.syncTaskAdapter.isShowCheckBox()) setProfileContextButtonNormalMode(); else setProfileContextButtonSelectMode(); if (!mGp.syncHistoryAdapter.isShowCheckBox()) setHistoryContextButtonNormalMode(); else setHistoryContextButtonSelectMode(); unsetOnKeyCallBackListener(); refreshOptionMenu(); }; private void setUiDisabled() { util.addDebugMsg(1, "I", "setUiDisabled entered"); enableMainUi = false; setOnKeyCallBackListener(new CallBackListener() { public boolean onCallBack(Context c, Object o1, Object[] o2) { Intent in = new Intent(); in.setAction(Intent.ACTION_MAIN); in.addCategory(Intent.CATEGORY_HOME); startActivity(in); return true; } }); if (!mGp.syncTaskAdapter.isShowCheckBox()) setProfileContextButtonNormalMode(); else setProfileContextButtonSelectMode(); if (!mGp.syncHistoryAdapter.isShowCheckBox()) setHistoryContextButtonNormalMode(); else setHistoryContextButtonSelectMode(); refreshOptionMenu(); }; private boolean isUiEnabled() { return enableMainUi; }; @SuppressLint("NewApi") final private void refreshOptionMenu() { util.addDebugMsg(2, "I", "refreshOptionMenu entered"); // if (Build.VERSION.SDK_INT>=11) // this.invalidateOptionsMenu(); supportInvalidateOptionsMenu(); }; private void startSyncTask(ArrayList<SyncTaskItem> alp) { String[] task_name = new String[alp.size()]; for (int i = 0; i < alp.size(); i++) task_name[i] = alp.get(i).getSyncTaskName(); try { mSvcClient.aidlStartSpecificSyncTask(task_name); // mMainTabHost.setCurrentTab(2); } catch (RemoteException e) { e.printStackTrace(); } }; private void syncThreadStarted() { util.addDebugMsg(1, "I", "startSyncThread entered"); setUiDisabled(); mGp.progressSpinView.setVisibility(LinearLayout.VISIBLE); mGp.progressSpinView.setBackgroundColor(mGp.themeColorList.dialog_msg_background_color); mGp.progressSpinView.bringToFront(); mGp.progressSpinSyncprof.setVisibility(TextView.VISIBLE); mGp.progressSpinCancel.setText(getString(R.string.msgs_progress_spin_dlg_sync_cancel)); mGp.progressSpinCancel.setEnabled(true); // CANCEL? mGp.progressSpinCancelListener = new View.OnClickListener() { public void onClick(View v) { NotifyEvent ntfy = new NotifyEvent(mContext); ntfy.setListener(new NotifyEventListener() { @Override public void positiveResponse(Context c, Object[] o) { try { mSvcClient.aidlCancelSyncTask(); } catch (RemoteException e) { e.printStackTrace(); } mGp.progressSpinCancel.setText(getString(R.string.msgs_progress_dlg_canceling)); mGp.progressSpinCancel.setEnabled(false); } @Override public void negativeResponse(Context c, Object[] o) { } }); commonDlg.showCommonDialog(true, "W", getString(R.string.msgs_sync_cancel_confirm), "", ntfy); } }; mGp.progressSpinCancel.setOnClickListener(mGp.progressSpinCancelListener); mGp.msgListView.setFastScrollEnabled(false); SchedulerUtil.setSchedulerInfo(mGp, mContext, null); LogUtil.flushLog(mContext, mGp); }; private void syncThreadEnded() { util.addDebugMsg(1, "I", "SyncThread ended"); LogUtil.flushLog(mContext, mGp); mGp.progressBarCancelListener = null; mGp.progressBarImmedListener = null; mGp.progressSpinCancelListener = null; mGp.progressBarCancel.setOnClickListener(null); mGp.progressSpinCancel.setOnClickListener(null); mGp.progressBarImmed.setOnClickListener(null); mGp.progressSpinView.setVisibility(LinearLayout.GONE); mGp.syncHistoryAdapter.notifyDataSetChanged(); setUiEnabled(); }; private ISvcCallback mSvcCallbackStub = new ISvcCallback.Stub() { @Override public void cbThreadStarted() throws RemoteException { mUiHandler.post(new Runnable() { @Override public void run() { syncThreadStarted(); } }); } @Override public void cbThreadEnded() throws RemoteException { mUiHandler.post(new Runnable() { @Override public void run() { syncThreadEnded(); } }); } @Override public void cbShowConfirmDialog(final String fp, final String method) throws RemoteException { mUiHandler.post(new Runnable() { @Override public void run() { showConfirmDialog(fp, method); } }); } @Override public void cbHideConfirmDialog() throws RemoteException { mUiHandler.post(new Runnable() { @Override public void run() { hideConfirmDialog(); } }); } @Override public void cbWifiStatusChanged(String status, String ssid) throws RemoteException { mUiHandler.post(new Runnable() { @Override public void run() { refreshOptionMenu(); if (mGp.syncTaskAdapter.isShowCheckBox()) setProfileContextButtonSelectMode(); else setProfileContextButtonNormalMode(); } }); } }; private static ISvcClient mSvcClient = null; private void openService(final NotifyEvent p_ntfy) { util.addDebugMsg(1, "I", "openService entered"); mSvcConnection = new ServiceConnection() { public void onServiceConnected(ComponentName arg0, IBinder service) { util.addDebugMsg(1, "I", "onServiceConnected entered"); mSvcClient = ISvcClient.Stub.asInterface(service); p_ntfy.notifyToListener(true, null); } public void onServiceDisconnected(ComponentName name) { mSvcConnection = null; util.addDebugMsg(1, "I", "onServiceDisconnected entered"); // mSvcClient=null; // synchronized(tcService) { // tcService.notify(); // } } }; Intent intmsg = new Intent(mContext, SyncService.class); intmsg.setAction("Bind"); bindService(intmsg, mSvcConnection, BIND_AUTO_CREATE); }; private void closeService() { util.addDebugMsg(1, "I", "closeService entered, conn=" + mSvcConnection); if (mSvcConnection != null) { // try { // if (mSvcClient!=null) mSvcClient.aidlStopService(); // } catch (RemoteException e) { // e.printStackTrace(); // } mSvcClient = null; unbindService(mSvcConnection); mSvcConnection = null; // Log.v("","close service"); } // Intent intent = new Intent(this, SyncService.class); // stopService(intent); }; final private void setCallbackListener() { util.addDebugMsg(1, "I", "setCallbackListener entered"); try { mSvcClient.setCallBack(mSvcCallbackStub); } catch (RemoteException e) { e.printStackTrace(); util.addDebugMsg(0, "E", "setCallbackListener error :" + e.toString()); } }; final private void unsetCallbackListener() { if (mSvcClient != null) { try { mSvcClient.removeCallBack(mSvcCallbackStub); } catch (RemoteException e) { e.printStackTrace(); util.addDebugMsg(0, "E", "unsetCallbackListener error :" + e.toString()); } } }; private void reshowDialogWindow() { if (mGp.dialogWindowShowed) { syncThreadStarted(); mGp.progressSpinSyncprof.setText(mGp.progressSpinSyncprofText); mGp.progressSpinMsg.setText(mGp.progressSpinMsgText); if (mGp.confirmDialogShowed) showConfirmDialog(mGp.confirmDialogFilePath, mGp.confirmDialogMethod); } } private void hideConfirmDialog() { mGp.confirmView.setVisibility(LinearLayout.GONE); }; private void showConfirmDialog(String fp, String method) { util.addDebugMsg(1, "I", "showConfirmDialog entered"); mGp.confirmDialogShowed = true; mGp.confirmDialogFilePath = fp; mGp.confirmDialogMethod = method; final NotifyEvent ntfy = new NotifyEvent(mContext); ntfy.setListener(new NotifyEventListener() { @Override public void positiveResponse(Context c, Object[] o) { mGp.confirmDialogShowed = false; try { mSvcClient.aidlConfirmReply((Integer) o[0]); } catch (RemoteException e) { e.printStackTrace(); } mGp.confirmYesListener = null; mGp.confirmYesAllListener = null; mGp.confirmNoListener = null; mGp.confirmNoAllListener = null; mGp.confirmCancelListener = null; mGp.confirmCancel.setOnClickListener(null); mGp.confirmYes.setOnClickListener(null); mGp.confirmYesAll.setOnClickListener(null); mGp.confirmNo.setOnClickListener(null); mGp.confirmNoAll.setOnClickListener(null); } @Override public void negativeResponse(Context c, Object[] o) { mGp.confirmDialogShowed = false; try { mSvcClient.aidlConfirmReply((Integer) o[0]); } catch (RemoteException e) { e.printStackTrace(); } mGp.confirmYesListener = null; mGp.confirmYesAllListener = null; mGp.confirmNoListener = null; mGp.confirmNoAllListener = null; mGp.confirmCancelListener = null; mGp.confirmCancel.setOnClickListener(null); mGp.confirmYes.setOnClickListener(null); mGp.confirmYesAll.setOnClickListener(null); mGp.confirmNo.setOnClickListener(null); mGp.confirmNoAll.setOnClickListener(null); } }); mGp.confirmView.setVisibility(LinearLayout.VISIBLE); mGp.confirmView.setBackgroundColor(mGp.themeColorList.dialog_msg_background_color); mGp.confirmView.bringToFront(); String msg_text = ""; if (method.equals(SMBSYNC_CONFIRM_REQUEST_COPY)) { msg_text = String.format(getString(R.string.msgs_mirror_confirm_copy_confirm), fp); } else if (method.equals(SMBSYNC_CONFIRM_REQUEST_DELETE_FILE)) { msg_text = String.format(getString(R.string.msgs_mirror_confirm_delete_file_confirm), fp); } else if (method.equals(SMBSYNC_CONFIRM_REQUEST_DELETE_DIR)) { msg_text = String.format(getString(R.string.msgs_mirror_confirm_delete_dir_confirm), fp); } mGp.confirmMsg.setText(msg_text); // Yes? mGp.confirmYesListener = new View.OnClickListener() { public void onClick(View v) { mGp.confirmView.setVisibility(LinearLayout.GONE); ntfy.notifyToListener(true, new Object[] { SMBSYNC_CONFIRM_RESP_YES }); } }; mGp.confirmYes.setOnClickListener(mGp.confirmYesListener); // YesAll? mGp.confirmYesAllListener = new View.OnClickListener() { public void onClick(View v) { mGp.confirmView.setVisibility(LinearLayout.GONE); ntfy.notifyToListener(true, new Object[] { SMBSYNC_CONFIRM_RESP_YESALL }); } }; mGp.confirmYesAll.setOnClickListener(mGp.confirmYesAllListener); // No? mGp.confirmNoListener = new View.OnClickListener() { public void onClick(View v) { mGp.confirmView.setVisibility(LinearLayout.GONE); ntfy.notifyToListener(false, new Object[] { SMBSYNC_CONFIRM_RESP_NO }); } }; mGp.confirmNo.setOnClickListener(mGp.confirmNoListener); // NoAll? mGp.confirmNoAllListener = new View.OnClickListener() { public void onClick(View v) { mGp.confirmView.setVisibility(LinearLayout.GONE); ntfy.notifyToListener(false, new Object[] { SMBSYNC_CONFIRM_RESP_NOALL }); } }; mGp.confirmNoAll.setOnClickListener(mGp.confirmNoAllListener); // Task cancel? mGp.confirmCancelListener = new View.OnClickListener() { public void onClick(View v) { mGp.confirmView.setVisibility(LinearLayout.GONE); // try { // mSvcClient.aidlCancelThread(); // } catch (RemoteException e) { // e.printStackTrace(); // } // mGp.progressSpinCancel.performClick(); ntfy.notifyToListener(false, new Object[] { SMBSYNC_CONFIRM_RESP_CANCEL }); } }; mGp.confirmCancel.setOnClickListener(mGp.confirmCancelListener); }; final private boolean checkJcifsOptionChanged() { boolean changed = false; String prevSmbLogLevel = mGp.settingsSmbLogLevel, prevSmbRcvBufSize = mGp.settingsSmbRcvBufSize, prevSmbSndBufSize = mGp.settingsSmbSndBufSize, prevSmbListSize = mGp.settingsSmbListSize, prevSmbMaxBuffers = mGp.settingsSmbMaxBuffers, prevSmbTcpNodelay = mGp.settingsSmbTcpNodelay, prevSmbLmCompatibility = mGp.settingsSmbLmCompatibility, prevSmbUseExtendedSecurity = mGp.settingsSmbUseExtendedSecurity; mGp.initJcifsOption(mGp.appContext); if (!mGp.settingsSmbLmCompatibility.equals(prevSmbLmCompatibility)) changed = true; else if (!mGp.settingsSmbUseExtendedSecurity.equals(prevSmbUseExtendedSecurity)) changed = true; if (!changed) { if (!mGp.settingsSmbLogLevel.equals(prevSmbLogLevel)) { changed = true; // Log.v("","logLevel"); } else if (!mGp.settingsSmbRcvBufSize.equals(prevSmbRcvBufSize)) { changed = true; // Log.v("","rcvBuff"); } else if (!mGp.settingsSmbSndBufSize.equals(prevSmbSndBufSize)) { changed = true; // Log.v("","sndBuff"); } else if (!mGp.settingsSmbListSize.equals(prevSmbListSize)) { changed = true; // Log.v("","listSize"); } else if (!mGp.settingsSmbMaxBuffers.equals(prevSmbMaxBuffers)) { changed = true; // Log.v("","maxBuff"); } else if (!mGp.settingsSmbTcpNodelay.equals(prevSmbTcpNodelay)) { changed = true; // Log.v("","tcpNodelay"); } } if (changed) { listSMBSyncOption(); commonDlg.showCommonDialog(false, "W", mContext.getString(R.string.msgs_smbsync_main_settings_jcifs_changed_restart), "", null); } return changed; }; private void saveTaskData() { util.addDebugMsg(2, "I", "saveTaskData entered"); if (!isTaskTermination) { if (!isTaskDataExisted() || mGp.msgListAdapter.resetDataChanged()) { ActivityDataHolder data = new ActivityDataHolder(); data.ml = mGp.msgListAdapter.getMessageList(); data.pl = mGp.syncTaskAdapter.getArrayList(); try { FileOutputStream fos = openFileOutput(SMBSYNC_SERIALIZABLE_FILE_NAME, MODE_PRIVATE); BufferedOutputStream bos = new BufferedOutputStream(fos, 4096 * 256); ObjectOutputStream oos = new ObjectOutputStream(bos); oos.writeObject(data); oos.flush(); oos.close(); util.addDebugMsg(1, "I", "Task data was saved."); } catch (Exception e) { e.printStackTrace(); util.addLogMsg("E", "saveTaskData error, " + e.toString()); util.addLogMsg("E", "StackTrace element, " + printStackTraceElement(e.getStackTrace())); } } } }; private String printStackTraceElement(StackTraceElement[] ste) { String st_msg = ""; for (int i = 0; i < ste.length; i++) { st_msg += "\n at " + ste[i].getClassName() + "." + ste[i].getMethodName() + "(" + ste[i].getFileName() + ":" + ste[i].getLineNumber() + ")"; } return st_msg; }; private void restoreTaskData() { util.addDebugMsg(2, "I", "restoreTaskData entered"); File lf = new File(mGp.applicationRootDirectory + "/" + SMBSYNC_SERIALIZABLE_FILE_NAME); if (lf.exists()) { try { // FileInputStream fis = openFileInput(SMBSYNC_SERIALIZABLE_FILE_NAME); FileInputStream fis = new FileInputStream(lf); BufferedInputStream bis = new BufferedInputStream(fis, 4096 * 256); ObjectInputStream ois = new ObjectInputStream(bis); ActivityDataHolder data = (ActivityDataHolder) ois.readObject(); ois.close(); lf.delete(); ArrayList<MsgListItem> o_ml = new ArrayList<MsgListItem>(); for (int i = 0; i < mGp.msgListAdapter.getCount(); i++) o_ml.add(mGp.msgListAdapter.getItem(i)); mGp.msgListAdapter.clear(); mGp.msgListAdapter.setMessageList(data.ml); for (int i = 0; i < o_ml.size(); i++) mGp.msgListAdapter.add(o_ml.get(i)); mGp.msgListAdapter.notifyDataSetChanged(); mGp.msgListAdapter.resetDataChanged(); mGp.syncTaskAdapter.clear(); mGp.syncTaskAdapter.setArrayList(data.pl); util.addDebugMsg(1, "I", "Task data was restored."); } catch (Exception e) { e.printStackTrace(); util.addLogMsg("E", "restoreTaskData error, " + e.toString()); util.addLogMsg("E", "StackTrace element, " + printStackTraceElement(e.getStackTrace())); } } }; private boolean isTaskDataExisted() { File lf = new File(getFilesDir() + "/" + SMBSYNC_SERIALIZABLE_FILE_NAME); return lf.exists(); }; private void deleteTaskData() { File lf = new File(mGp.applicationRootDirectory + "/" + SMBSYNC_SERIALIZABLE_FILE_NAME); if (lf.exists()) { lf.delete(); util.addDebugMsg(1, "I", "RestartData was delete."); } }; } class ActivityDataHolder implements Serializable { private static final long serialVersionUID = 1L; ArrayList<MsgListItem> ml = null; ArrayList<SyncTaskItem> pl = null; }