@Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.line_list);

    // Setup the list
    adapter = new IconAdapter<FileWrapper>(this, R.layout.line_list_item);
    ListView list = (ListView) findViewById(R.id.list);
    list.setAdapter(adapter);
    list.setOnItemClickListener(this);

    // Load Directory
    if (savedInstanceState != null) {
      backStack = savedInstanceState.getParcelableArrayList("BACKSTACK");
    }

    if (backStack == null || backStack.size() == 0) {
      backStack = new ArrayList<BackStackItem>();
      String startPath =
          (startDirectory == null || startDirectory.isEmpty())
              ? Environment.getExternalStorageDirectory().getPath()
              : startDirectory;
      backStack.add(new BackStackItem(startPath, false));
    }

    wrapFiles();
    this.setVolumeControlStream(AudioManager.STREAM_MUSIC);
  }
  /**
   * Returns and shows pending/shown SuperCardToasts from orientation change and reattaches any
   * OnToastButtonClickListeners and any OnToastDismissListeners. <br>
   * IMPORTANT: Use this method to save OnToastButtonClickListeners and OnToastDismissListenerHolder
   * on devices with API < 11. Otherwise use onRestoreState(Bundle bundle, Activity activity) as
   * that method uses a retained fragment to save listeners. <br>
   *
   * @param bundle Use onCreate() bundle
   * @param activity The current activity
   * @param onToastButtonClickListeners List of any attached OnToastButtonClickListenerHolders from
   *     previous orientation
   * @param onToastDismissListeners List of any attached OnToastDismissListenerHolders from previous
   *     orientation
   */
  public static void onRestoreState(
      Bundle bundle,
      Activity activity,
      List<OnToastButtonClickListenerHolder> onToastButtonClickListeners,
      List<OnToastDismissListenerHolder> onToastDismissListeners) {

    if (bundle == null) {

      return;
    }

    Parcelable[] savedArray = bundle.getParcelableArray(BUNDLE_TAG);

    int i = 0;

    if (savedArray != null) {

      for (Parcelable parcelable : savedArray) {

        i++;

        new SuperCardToast(
            activity, (Style) parcelable, onToastButtonClickListeners, onToastDismissListeners, i);
      }
    }
  }
 private void checkAddCity() {
   if (WeatherData.getCityInfo(0).mShowType
       == com.moji.mjweather.data.CityWeatherInfo.ShowType.ST_NOSET) {
     Gl.setHandler(MainHandler);
     Intent intent = new Intent(this, AddCityActivity.class);
     Bundle bundle = new Bundle();
     bundle.putInt("cityindex", 0);
     bundle.putBoolean("isNoDisplayLocation", true);
     intent.putExtras(bundle);
     startActivity(intent);
   }
 }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Bundle parms = getIntent().getExtras();
    int sessionId = parms.getInt("sess_id");
    profileId = parms.getInt("prof_id");

    if (savedInstanceState != null) {
      sessionId = savedInstanceState.getInt("sess_id");
    }

    if (sessionId == 0) {
      loginFailure();
    } else {
      loadContext(sessionId);
    }
  }
 /**
  * Factory method for this fragment class. Constructs a new fragment for the given page number.
  */
 public static ScreenSlidePageFragment create(int pageNumber) {
   ScreenSlidePageFragment fragment = new ScreenSlidePageFragment();
   Bundle args = new Bundle();
   args.putInt(ARG_PAGE, pageNumber);
   fragment.setArguments(args);
   return fragment;
 }
  /**
   * Creates new instance of <tt>ActionBarToggleFragment</tt> with given description(can be empty
   * but not <tt>null</tt>).
   *
   * @param labelText toggle button's description(can be empty, but not <tt>null</tt>).
   * @return new instance of <tt>ActionBarToggleFragment</tt> parametrized with description
   *     argument.
   */
  public static ActionBarToggleFragment create(String labelText) {
    ActionBarToggleFragment fragment = new ActionBarToggleFragment();

    Bundle args = new Bundle();
    args.putString(ARG_LABEL_TEXT, labelText);
    fragment.setArguments(args);

    return fragment;
  }
Example #7
0
 @Override
 public void onClick(View v) {
   Message msg = new Message();
   msg.what = clickIndex;
   msg.arg1 = position;
   Bundle b = new Bundle();
   b.putSerializable(BUNDLE_KEY_LIDATA, list.get(position));
   msg.setData(b);
   mHandle.sendMessage(msg);
 }
Example #8
0
  /**
   * This method is called by SDL using JNI. Shows the messagebox from UI thread and block calling
   * thread. buttonFlags, buttonIds and buttonTexts must have same length.
   *
   * @param buttonFlags array containing flags for every button.
   * @param buttonIds array containing id for every button.
   * @param buttonTexts array containing text for every button.
   * @param colors null for default or array of length 5 containing colors.
   * @return button id or -1.
   */
  public int messageboxShowMessageBox(
      final int flags,
      final String title,
      final String message,
      final int[] buttonFlags,
      final int[] buttonIds,
      final String[] buttonTexts,
      final int[] colors) {

    messageboxSelection[0] = -1;

    // sanity checks

    if ((buttonFlags.length != buttonIds.length) && (buttonIds.length != buttonTexts.length)) {
      return -1; // implementation broken
    }

    // collect arguments for Dialog

    final Bundle args = new Bundle();
    args.putInt("flags", flags);
    args.putString("title", title);
    args.putString("message", message);
    args.putIntArray("buttonFlags", buttonFlags);
    args.putIntArray("buttonIds", buttonIds);
    args.putStringArray("buttonTexts", buttonTexts);
    args.putIntArray("colors", colors);

    // trigger Dialog creation on UI thread

    runOnUiThread(
        new Runnable() {
          @Override
          public void run() {
            showDialog(dialogs++, args);
          }
        });

    // block the calling thread

    synchronized (messageboxSelection) {
      try {
        messageboxSelection.wait();
      } catch (InterruptedException ex) {
        ex.printStackTrace();
        return -1;
      }
    }

    // return selected value

    return messageboxSelection[0];
  }
Example #9
0
  @SuppressLint("DefaultLocale")
  @Override
  public void onCreate(Bundle savedInstanceState) {
    // TODO refactor
    super.onCreate(savedInstanceState);

    getSupportActionBar().setHomeButtonEnabled(true);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    String license = "";
    Bundle bundle = getIntent().getExtras();
    if (bundle != null) {
      license = bundle.getString(KEY_BU_LICENSE_NAME);
    }
    setContentView(R.layout.activity_licensing);
    setTitle(license.toUpperCase());
    final TextView textView = (TextView) findViewById(R.id.license);
    final ProgressBar progressBar = (ProgressBar) findViewById(R.id.progress);
    final ThreadedLicenseReader reader = new ThreadedLicenseReader(this, license);
    reader.setOnLicenseReadListener(
        new OnLicenseReadListener() {
          @Override
          public void onLicenseRead() {
            runOnUiThread(
                new Runnable() {
                  @Override
                  public void run() {
                    String license = reader.getLicense();
                    if (license != null) {
                      textView.setText(license);
                    }
                    progressBar.setVisibility(View.INVISIBLE);
                    textView.setVisibility(View.VISIBLE);
                  }
                });
          }
        });
    reader.start();
  }
Example #10
0
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (savedInstanceState == null) {
      x = 50;
    } else {
      x = savedInstanceState.getInt("x");
    }
    y = 50;
    vw = new MyView(this);
    vw.setFocusable(true);
    vw.setFocusableInTouchMode(true);
    setContentView(vw);
  }
  /**
   * Saves pending/shown SuperCardToasts to a bundle. <br>
   *
   * @param bundle Use onSaveInstanceState() bundle
   */
  public static void onSaveState(Bundle bundle) {

    Style[] list = new Style[ManagerSuperCardToast.getInstance().getList().size()];

    LinkedList<SuperCardToast> lister = ManagerSuperCardToast.getInstance().getList();

    for (int i = 0; i < list.length; i++) {

      list[i] = new Style(lister.get(i));
    }

    bundle.putParcelableArray(BUNDLE_TAG, list);

    SuperCardToast.cancelAllSuperCardToasts();
  }
  /**
   * Returns and shows pending/shown SuperCardToasts from orientation change. <br>
   * IMPORTANT: On devices > API 11 this method will automatically save any OnClickListeners and
   * OnDismissListeners via retained Fragment. <br>
   *
   * @param bundle Use onCreate() bundle
   * @param activity The current activity
   */
  public static void onRestoreState(Bundle bundle, Activity activity) {

    if (bundle == null) {

      return;
    }

    Parcelable[] savedArray = bundle.getParcelableArray(BUNDLE_TAG);

    int i = 0;

    if (savedArray != null) {

      for (Parcelable parcelable : savedArray) {

        i++;

        new SuperCardToast(activity, (Style) parcelable, null, null, i);
      }
    }
  }
Example #13
0
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    try {
      mSharedPreferences = Prefs.getSharedPreferences(this);
    } catch (NullPointerException e) {
      if (BuildConfig.DEBUG) {
        Log.w("[" + TAG + "]", "mSharedPreferences == NullPointerException :" + e.getMessage());
      }
    }

    mSharedPreferences.registerOnSharedPreferenceChangeListener(this);

    if (Prefs.getThemeType(this) == false) {
      mThemeId = R.style.AppTheme_Light;
      setTheme(mThemeId);
    } else {
      mThemeId = R.style.AppTheme_Dark;
      setTheme(mThemeId);
    }

    // Eula.showDisclaimer( this );
    Eula.showEula(this, getApplicationContext());

    mActionBar = getActionBar();
    if (mActionBar != null) {
      mActionBar.setDisplayHomeAsUpEnabled(false);
      mActionBar.setDisplayShowHomeEnabled(true);
      mActionBar.setDisplayShowTitleEnabled(true);
    } else {
      if (BuildConfig.DEBUG) {
        Log.w("[" + TAG + "]", "mActionBar == null");
      }
    }

    Bundle extras = getIntent().getExtras();
    if (extras != null) {
      this.setTitle(extras.getString("dir") + " :: " + getString(R.string.app_name));
    } else {
      this.setTitle(" :: " + getString(R.string.app_name));
    }

    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    tvDisplay = (TextView) findViewById(R.id.tvDisplay);

    bRename = (Button) findViewById(R.id.bRename);
    bSettings = (Button) findViewById(R.id.bSettings);
    bHelp = (Button) findViewById(R.id.bHelp);
    bExit = (Button) findViewById(R.id.bExit);

    bRename.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View v) {
            Intent openAndroidFileBrowser = new Intent("com.scto.filerenamer.ANDROIDFILEBROWSER");
            openAndroidFileBrowser.putExtra("what", "renamer");
            openAndroidFileBrowser.putExtra("theme", mThemeId);
            startActivity(openAndroidFileBrowser);
          }
        });

    bSettings.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View v) {
            Intent openPreferencesActivity = new Intent("com.scto.filerenamer.PREFERENCESACTIVITY");
            startActivity(openPreferencesActivity);
          }
        });

    bHelp.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View v) {
            FragmentManager fm = getSupportFragmentManager();
            HelpDialog helpDialog = new HelpDialog();
            helpDialog.show(fm, "dlg_help");
          }
        });

    bExit.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View v) {
            FragmentManager fm = getSupportFragmentManager();
            ExitDialog exitDialog = new ExitDialog();
            exitDialog.show(fm, "dlg_exit");
          }
        });

    /*
    ChangeLog cl = new ChangeLog( this );
    if( cl.firstRun() )
    {
    	cl.getLogDialog().show();
    }
    */
    init();
  }
Example #14
0
  @Override
  protected Dialog onCreateDialog(int ignore, Bundle args) {

    // TODO set values from "flags" to messagebox dialog

    // get colors

    int[] colors = args.getIntArray("colors");
    int backgroundColor;
    int textColor;
    int buttonBorderColor;
    int buttonBackgroundColor;
    int buttonSelectedColor;
    if (colors != null) {
      int i = -1;
      backgroundColor = colors[++i];
      textColor = colors[++i];
      buttonBorderColor = colors[++i];
      buttonBackgroundColor = colors[++i];
      buttonSelectedColor = colors[++i];
    } else {
      backgroundColor = Color.TRANSPARENT;
      textColor = Color.TRANSPARENT;
      buttonBorderColor = Color.TRANSPARENT;
      buttonBackgroundColor = Color.TRANSPARENT;
      buttonSelectedColor = Color.TRANSPARENT;
    }

    // create dialog with title and a listener to wake up calling thread

    final Dialog dialog = new Dialog(this);
    dialog.setTitle(args.getString("title"));
    dialog.setCancelable(false);
    dialog.setOnDismissListener(
        new DialogInterface.OnDismissListener() {
          @Override
          public void onDismiss(DialogInterface unused) {
            synchronized (messageboxSelection) {
              messageboxSelection.notify();
            }
          }
        });

    // create text

    TextView message = new TextView(this);
    message.setGravity(Gravity.CENTER);
    message.setText(args.getString("message"));
    if (textColor != Color.TRANSPARENT) {
      message.setTextColor(textColor);
    }

    // create buttons

    int[] buttonFlags = args.getIntArray("buttonFlags");
    int[] buttonIds = args.getIntArray("buttonIds");
    String[] buttonTexts = args.getStringArray("buttonTexts");

    final SparseArray<Button> mapping = new SparseArray<Button>();

    LinearLayout buttons = new LinearLayout(this);
    buttons.setOrientation(LinearLayout.HORIZONTAL);
    buttons.setGravity(Gravity.CENTER);
    for (int i = 0; i < buttonTexts.length; ++i) {
      Button button = new Button(this);
      final int id = buttonIds[i];
      button.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              messageboxSelection[0] = id;
              dialog.dismiss();
            }
          });
      if (buttonFlags[i] != 0) {
        // see SDL_messagebox.h
        if ((buttonFlags[i] & 0x00000001) != 0) {
          mapping.put(KeyEvent.KEYCODE_ENTER, button);
        }
        if ((buttonFlags[i] & 0x00000002) != 0) {
          mapping.put(111, button); /* API 11: KeyEvent.KEYCODE_ESCAPE */
        }
      }
      button.setText(buttonTexts[i]);
      if (textColor != Color.TRANSPARENT) {
        button.setTextColor(textColor);
      }
      if (buttonBorderColor != Color.TRANSPARENT) {
        // TODO set color for border of messagebox button
      }
      if (buttonBackgroundColor != Color.TRANSPARENT) {
        Drawable drawable = button.getBackground();
        if (drawable == null) {
          // setting the color this way removes the style
          button.setBackgroundColor(buttonBackgroundColor);
        } else {
          // setting the color this way keeps the style (gradient, padding, etc.)
          drawable.setColorFilter(buttonBackgroundColor, PorterDuff.Mode.MULTIPLY);
        }
      }
      if (buttonSelectedColor != Color.TRANSPARENT) {
        // TODO set color for selected messagebox button
      }
      buttons.addView(button);
    }

    // create content

    LinearLayout content = new LinearLayout(this);
    content.setOrientation(LinearLayout.VERTICAL);
    content.addView(message);
    content.addView(buttons);
    if (backgroundColor != Color.TRANSPARENT) {
      content.setBackgroundColor(backgroundColor);
    }

    // add content to dialog and return

    dialog.setContentView(content);
    dialog.setOnKeyListener(
        new Dialog.OnKeyListener() {
          @Override
          public boolean onKey(DialogInterface d, int keyCode, KeyEvent event) {
            Button button = mapping.get(keyCode);
            if (button != null) {
              if (event.getAction() == KeyEvent.ACTION_UP) {
                button.performClick();
              }
              return true; // also for ignored actions
            }
            return false;
          }
        });

    return dialog;
  }
 @Override
 protected void onSaveInstanceState(Bundle outState) {
   super.onSaveInstanceState(outState);
   if (this.session != null) outState.putInt("sess_id", this.session.ID);
 }
 @Override
 protected void onSaveInstanceState(Bundle aState) {
   super.onSaveInstanceState(aState);
   aState.putParcelableArrayList("BACKSTACK", backStack);
 }
Example #17
0
 public void onSaveInstanceState(Bundle outState) {
   super.onSaveInstanceState(outState);
   outState.putInt("x", x);
 }
Example #18
0
 @Override
 protected void onSaveInstanceState(Bundle outState) {
   outState.putInt("theme", mThemeId);
   super.onSaveInstanceState(outState);
 }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    // locks the screen in portrait mode
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

    super.onCreate(savedInstanceState);
    setContentView(R.layout.downloader);
    mtext = (TextView) findViewById(R.id.mtext);
    progress_text = (TextView) findViewById(R.id.progress_text);
    progress_download = (ProgressBar) findViewById(R.id.progress_download);
    // resume capability

    paused = false;
    resume_pause = (Button) findViewById(R.id.resume);

    // Create and launch the download thread
    downloadThread = new DownloadThread(this);
    downloadThread.start();

    // Create the Handler. It will implicitly bind to the Looper
    // that is internally created for this thread (since it is the UI thread)
    handler = new Handler();

    resume_pause.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View v) {
            if (!paused) {
              paused = true;
              resume_pause.setText("Resume");
              // writeProgress(completed_downloads,total_files_to_download);
              downloadThread.requestStop();
              downloadThread = null;

            } else {
              resume_pause.setText("Pause");
              paused = false;

              initial_value = readProgress()[0];
              final_value = links.size();

              for (int i = initial_value; i < links.size(); i++) {
                downloadThread = new DownloadThread(download_photos.this);
                downloadThread.start();
                downloadThread.enqueueDownload(
                    new DownloadTask(
                        links.get(i), path, i + 1, links.size(), download_photos.this));
              }
            }
          }
        });

    // load preferences for this activity
    mPrefs = getSharedPreferences("COMMON", MODE_PRIVATE);

    // This declaration is solely meant for reading the checkbox preference for downloading high res
    // pics.
    SharedPreferences dl_prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());

    // The global variable is set after reading the  checkbox preference.
    dl_high_res_pics = dl_prefs.getBoolean("download_high_res", false);

    // load fb access token and its expiry values
    String access_token = mPrefs.getString("access_token", null);
    long expires = mPrefs.getLong("access_expires", 0);

    if (access_token != null) {
      facebook.setAccessToken(access_token);
    }
    if (expires != 0) {
      facebook.setAccessExpires(expires);
    }

    // get friend_name and album_name from the intent which started this activity
    Intent starting_intent = getIntent();
    album_id = starting_intent.getStringExtra("id");
    album_name = starting_intent.getStringExtra("name");
    friend_name = starting_intent.getStringExtra("friend_name");

    // real album and friend name may contain characters not suitable for file names.
    // regex pattern includes most of the invalid characters in file names
    legal_album_name = album_name.replaceAll("[.\\\\/:*?\"<>|]?[\\\\/:*?\"<>|]*", "");
    legal_friend_name = friend_name.replaceAll("[.\\\\/:*?\"<>|]?[\\\\/:*?\"<>|]*", "");

    // initialise the directory structure for download
    path =
        new File(
            Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)
                + "/"
                + getText(R.string.app_name)
                + "/"
                + legal_friend_name
                + "/"
                + legal_album_name);
    if (dl_high_res_pics)
      path = new File(path.toString() + "/" + getText(R.string.folder_name_high_res));

    resume_file = new File(path, "resume.txt");
    // implements actions to done after receiving json object
    class meRequestListener extends BaseRequestListener {
      @Override
      public void onComplete(String response, Object state) {
        try {
          Log.i(TAG, response);
          json = Util.parseJson(response);

          // photos are in the form of a json array
          child = json.getJSONArray("data");

          int total = child.length();

          // contains links to photos
          links = new ArrayList<String>(total);

          // adds link to each photo to our list after replacing the "https" from url
          // DownloadManager does not support https in gingerbread
          for (int i = 0; i < total; i++) {
            photo_json = child.getJSONObject(i);

            if (dl_high_res_pics) {
              JSONArray image_set = photo_json.getJSONArray("images");

              // highest resolution picture has the index zero in the images jsonarray
              JSONObject highest_res_pic = image_set.getJSONObject(0);
              String http_replaced =
                  highest_res_pic.getString("source").replaceFirst("https", "http");
              links.add(i, http_replaced);
            } else {
              // source property of the json object points to the photo's link
              String http_replaced = photo_json.getString("source").replaceFirst("https", "http");
              links.add(i, http_replaced);
            }
          }

          download_photos.this.runOnUiThread(
              new Runnable() {
                public void run() {
                  //	mytask = new DownloadImageTask();
                  //	mytask.execute(links);
                  // start downloading using asynctask
                  // new DownloadImageTask().execute(links);
                  // downloadThread.setPath(path);
                  // downloadThread.setWholeTasks(links.size());
                  if (resume_file.exists()) {

                    initial_value = readProgress()[0];
                    final_value = links.size();
                    // case if the task is already completed
                    if (initial_value == final_value) {
                      completed = true;
                      resume_pause.setVisibility(View.GONE);

                      progress_download.setMax(final_value);
                      progress_download.setProgress(0); // bug in progress bar
                      progress_download.setProgress(initial_value);

                      progress_text.setText("Completed.");
                      mtext.setText(
                          getText(R.string.download_textview_message_1)
                              + " "
                              + path.toString()
                              + ". ");

                    }

                    // case if some of the photos are already downloaded
                    else {
                      progress_download.setMax(links.size());
                      // progress_download.setProgress(0);	//bug in progress bar
                      progress_download.setProgress(initial_value);

                      // N.B if i= initial_value -1, then one image will be downloaded again. so to
                      // save cost we start with i = initial_value
                      for (int i = initial_value; i < links.size(); i++) {
                        mtext.setText(
                            getText(R.string.download_textview_message_1)
                                + " "
                                + path.toString()
                                + ". ");
                        // downloadThread.setRunningTask(i + 1);
                        downloadThread.enqueueDownload(
                            new DownloadTask(
                                links.get(i), path, i + 1, final_value, download_photos.this));
                      }
                    }
                  }

                  // case if the task is entirely new task
                  else {
                    for (int i = 0; i < links.size(); i++) {
                      mtext.setText(
                          getText(R.string.download_textview_message_1)
                              + " "
                              + path.toString()
                              + ". ");
                      // downloadThread.setRunningTask(i + 1);
                      downloadThread.enqueueDownload(
                          new DownloadTask(
                              links.get(i), path, i + 1, links.size(), download_photos.this));
                    }
                  }
                }
              });
        } catch (JSONException ex) {
          Log.e(TAG, "JSONEXception : " + ex.getMessage());
        }
      }
    }

    // makes asynchronous request to facebook graph api
    // the actions to be performed after receiving json response is implemented above

    Bundle parameters = new Bundle();

    // facebook returns only 25 photos when limit is not specified.
    parameters.putString("limit", max_photos_in_album);
    if (!completed) mAsyncRunner.request(album_id + "/photos", parameters, new meRequestListener());

    if (!facebook.isSessionValid()) {
      facebook.authorize(
          this,
          permissions,
          new DialogListener() {

            // save fb access token and its expiry values to prefernces of this activity
            @Override
            public void onComplete(Bundle values) {
              SharedPreferences.Editor editor = mPrefs.edit();
              editor.putString("access_token", facebook.getAccessToken());
              editor.putLong("access_expires", facebook.getAccessExpires());
              editor.commit();
            }

            @Override
            public void onFacebookError(FacebookError error) {
              Log.e(TAG, "Facebook Error : " + error.getMessage());
            }

            @Override
            public void onError(DialogError e) {
              Log.e(TAG, e.getMessage());
            }

            @Override
            public void onCancel() {
              // do nothing LOL :-)
            }
          });
    }
  }