Android Open Source - Tasque-for-Android External Problems Fragment






From Project

Back to project page Tasque-for-Android.

License

The source code is released under:

MIT License

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

Java Source Code

package com.bustiblelemons.tasque.splash;
// www  .  j a  va 2s  . co  m
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnTouchListener;
import android.widget.TextView;

import com.actionbarsherlock.app.SherlockFragment;
import com.bustiblelemons.tasque.R;
import com.bustiblelemons.tasque.utilities.Utility;

public class ExternalProblemsFragment extends SherlockFragment implements OnTouchListener {

  private View view;
  private TextView hint;
  private Context context;
  private static Thread checker;
  private static Handler handler;
  private static final int EXTERNAL_AVAILABLE = 100002;
  private static final int FOUND_DATABASE = 100003;
  public static final int DATABASE_COPIED = 100004;
  public static final int DATABASE_NOT_FOUND = 100005;

  public interface OnDatabaseSearchFinished {
    public void databaseSearchFinished(int result);
  }

  private OnDatabaseSearchFinished searchFinishedCallback;

  @Override
  public void onAttach(Activity activity) {
    super.onAttach(activity);
    if (activity instanceof OnDatabaseSearchFinished) {
      searchFinishedCallback = (OnDatabaseSearchFinished) activity;
    } else {
      throw new ClassCastException(activity.getClass().getSimpleName() + " should implement interface "
          + OnDatabaseSearchFinished.class.getSimpleName());
    }
  }

  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    view = inflater.inflate(R.layout.fragment_external_problems, null);
    hint = (TextView) view.findViewById(R.id.fragment_external_problems_hint);
    return view;
  }

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    context = getActivity().getApplicationContext();
    handler = new Handler() {
      public void handleMessage(android.os.Message msg) {
        switch (msg.arg1) {
        case EXTERNAL_AVAILABLE:
          hint.setText(R.string.fragment_external_problems_hint_memory_mounted);
          break;
        case DATABASE_NOT_FOUND:
          searchFinishedCallback.databaseSearchFinished(DATABASE_NOT_FOUND);
          checker.stop();
          break;
        case FOUND_DATABASE:
          try {
            Utility.copyDatabase(context);
          } finally {
            checker.stop();
            searchFinishedCallback.databaseSearchFinished(DATABASE_COPIED);
          }
          break;
        }
      };
    };
    checker = new Thread(new Runnable() {
      Handler mHandler = handler;

      @Override
      public void run() {
        try {
          Thread.sleep(3000);
          if (Utility.isExtenalAvailable()) {
            Message msg = handler.obtainMessage();
            if (Utility.isDatabaseSynced(context)) {
              msg.arg1 = FOUND_DATABASE;
            } else {
              msg.arg1 = DATABASE_NOT_FOUND;
            }
            mHandler.sendMessage(msg);
          }
        } catch (InterruptedException e) {
          e.printStackTrace();
        }

      }
    });
    checker.start();
  }

  @Override
  public boolean onTouch(View v, MotionEvent event) {
    return true;
  }

}




Java Source Code List

com.bustiblelemons.tasque.database.DatabaseAdapter.java
com.bustiblelemons.tasque.database.Database.java
com.bustiblelemons.tasque.frontend.Alarms.java
com.bustiblelemons.tasque.frontend.Category.java
com.bustiblelemons.tasque.frontend.Note.java
com.bustiblelemons.tasque.frontend.Task.java
com.bustiblelemons.tasque.main.CategoriesFragment.java
com.bustiblelemons.tasque.main.CompletedTasksFragment.java
com.bustiblelemons.tasque.main.NotesAdapter.java
com.bustiblelemons.tasque.main.NotesFragment.java
com.bustiblelemons.tasque.main.RightSideFragmentPocketListener.java
com.bustiblelemons.tasque.main.SpinnerAdapter.java
com.bustiblelemons.tasque.main.TasqueAdapter.java
com.bustiblelemons.tasque.main.TasqueCategoryAdapter.java
com.bustiblelemons.tasque.main.TasqueGroupFragment.java
com.bustiblelemons.tasque.main.TasqueRTMCategoryAdapter.java
com.bustiblelemons.tasque.main.Tasque.java
com.bustiblelemons.tasque.rtm.RTMAuthFragment.java
com.bustiblelemons.tasque.rtm.RTMBackend.java
com.bustiblelemons.tasque.rtm.RTMConnectivityReceiver.java
com.bustiblelemons.tasque.rtm.RTMLoginFromSettings.java
com.bustiblelemons.tasque.rtm.RTMSyncBroadcastReceiver.java
com.bustiblelemons.tasque.rtm.RTMSyncService.java
com.bustiblelemons.tasque.rtm.SynchronizingFragment.java
com.bustiblelemons.tasque.settings.RTMBackendFragmentSettings.java
com.bustiblelemons.tasque.settings.SettingsActivity.java
com.bustiblelemons.tasque.settings.SettingsUtil.java
com.bustiblelemons.tasque.splash.ExportToExternalFragment.java
com.bustiblelemons.tasque.splash.ExternalProblemsFragment.java
com.bustiblelemons.tasque.splash.ImporterActivity.java
com.bustiblelemons.tasque.splash.Splash.java
com.bustiblelemons.tasque.tutorial.OSChooserFragment.java
com.bustiblelemons.tasque.tutorial.OSListAdapter.java
com.bustiblelemons.tasque.tutorial.SynchronizeTutorialActivity.java
com.bustiblelemons.tasque.tutorial.SynchronizedFilesAdapter.java
com.bustiblelemons.tasque.tutorial.TutorialTabFragment.java
com.bustiblelemons.tasque.utilities.Connection.java
com.bustiblelemons.tasque.utilities.PermissionParser.java
com.bustiblelemons.tasque.utilities.PriorityParser.java
com.bustiblelemons.tasque.utilities.Utility.java
com.bustiblelemons.tasque.utilities.Values.java