コード例 #1
0
ファイル: Settings.java プロジェクト: Drwang2015/schedule
 @Override
 public void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.settings);
   this.setTitle(R.string.setting);
   sp = PreferenceManager.getDefaultSharedPreferences(this);
   edit = sp.edit();
   Button widgettheme = (Button) findViewById(R.id.widgettheme);
   Button settime = (Button) findViewById(R.id.settime);
   Button save = (Button) findViewById(R.id.set_save);
   nc = (CheckBox) findViewById(R.id.nightcheck);
   rs = (CheckBox) findViewById(R.id.ringswitch);
   widgettheme.setOnClickListener(
       new View.OnClickListener() {
         @Override
         public void onClick(View Button) {
           AlertDialog.Builder ad =
               new AlertDialog.Builder(Settings.this)
                   .setTitle("选择颜色?")
                   .setItems(
                       color,
                       new DialogInterface.OnClickListener() {
                         @Override
                         public void onClick(DialogInterface p1, int p2) {
                           edit.putInt("widgetTextColor", colori[p2]);
                           edit.commit();
                         }
                       });
           ad.show();
         }
       });
   settime.setOnClickListener(
       new View.OnClickListener() {
         @Override
         public void onClick(View Button) {
           Intent set = new Intent(Settings.this, Settime.class);
           startActivity(set);
           return;
         }
       });
   save.setOnClickListener(
       new View.OnClickListener() {
         public void onClick(View Button) {
           save();
           return;
         }
       });
   nc.setChecked(sp.getBoolean("nightmode", false));
   if (sp.getBoolean("timewrong", false) == true) {
     rs.setChecked(false);
     rs.setClickable(false);
   }
 }
コード例 #2
0
  private void finishWithPath(String path) {
    if (pathSettingKey != null && !pathSettingKey.isEmpty()) {
      SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
      SharedPreferences.Editor editor = settings.edit();
      editor.putString(pathSettingKey, path);
      editor.commit();
    }

    Intent intent = new Intent();
    intent.putExtra("PATH", path);
    setResult(RESULT_OK, intent);
    finish();
  }
コード例 #3
0
  // code which handles the action for each menu item
  public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
      case R.id.settings:
        {
          Intent preferences_intent = new Intent();
          preferences_intent.setComponent(
              new ComponentName(download_photos.this, preferences.class));
          preferences_intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
          getApplicationContext().startActivity(preferences_intent);

          return true;
        }
      case R.id.logout:
        {
          try {
            download_photos.this.facebook.logout(getApplicationContext());
          } catch (IOException e) {
            e.printStackTrace();
          }

          mPrefs = getSharedPreferences("COMMON", MODE_PRIVATE);

          SharedPreferences.Editor editor = mPrefs.edit();
          editor.putString("access_token", null);
          editor.putLong("access_expires", 0);
          editor.putBoolean("logout", true);
          editor.commit();
          finish();
          return true;
        }
      case R.id.about:
        {
          // shows our customized about dialog
          AboutDialog about = new AboutDialog(this);

          about.show();
          return true;
        }
        // lets deal with default case
      default:
        return super.onOptionsItemSelected(item);
    }
  }
コード例 #4
0
  @Override
  protected void onStop() {
    SharedPreferences prefs = getPreferences(Context.MODE_PRIVATE);
    SharedPreferences.Editor editor = prefs.edit();

    editor.putInt("level", this.level);
    editor.putString("map", game.getLabyrinth().getJsonMap());
    editor.putString("howdy", game.getJsonHowdy());

    String allDoneLevelsString = "";

    for (String s : allDoneLevels) {
      allDoneLevelsString += s + ",";
    }

    if (allDoneLevelsString.length() > 0) {
      editor.putString(
          "doneLevels", allDoneLevelsString.substring(0, allDoneLevelsString.length() - 1));
    }

    editor.commit();

    super.onStop();
  }
コード例 #5
0
ファイル: Godot.java プロジェクト: gokudomatic/godot
  @Override
  protected void onCreate(Bundle icicle) {

    Log.d("GODOT", "** GODOT ACTIVITY CREATED HERE ***\n");

    super.onCreate(icicle);
    _self = this;
    Window window = getWindow();
    window.addFlags(
        WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
            | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

    // check for apk expansion API
    if (true) {
      boolean md5mismatch = false;
      command_line = getCommandLine();
      boolean use_apk_expansion = false;
      String main_pack_md5 = null;
      String main_pack_key = null;

      List<String> new_args = new LinkedList<String>();

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

        boolean has_extra = i < command_line.length - 1;
        if (command_line[i].equals("-use_apk_expansion")) {
          use_apk_expansion = true;
        } else if (has_extra && command_line[i].equals("-apk_expansion_md5")) {
          main_pack_md5 = command_line[i + 1];
          i++;
        } else if (has_extra && command_line[i].equals("-apk_expansion_key")) {
          main_pack_key = command_line[i + 1];
          SharedPreferences prefs = getSharedPreferences("app_data_keys", MODE_PRIVATE);
          Editor editor = prefs.edit();
          editor.putString("store_public_key", main_pack_key);

          editor.commit();
          i++;
        } else if (command_line[i].trim().length() != 0) {
          new_args.add(command_line[i]);
        }
      }

      if (new_args.isEmpty()) {
        command_line = null;
      } else {

        command_line = new_args.toArray(new String[new_args.size()]);
      }
      if (use_apk_expansion && main_pack_md5 != null && main_pack_key != null) {
        // check that environment is ok!
        if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
          Log.d("GODOT", "**ERROR! No media mounted!");
          // show popup and die
        }

        // Build the full path to the app's expansion files
        try {
          expansion_pack_path =
              Environment.getExternalStorageDirectory().toString()
                  + "/Android/obb/"
                  + this.getPackageName();
          expansion_pack_path +=
              "/"
                  + "main."
                  + getPackageManager().getPackageInfo(getPackageName(), 0).versionCode
                  + "."
                  + this.getPackageName()
                  + ".obb";
        } catch (Exception e) {
          e.printStackTrace();
        }

        File f = new File(expansion_pack_path);

        boolean pack_valid = true;
        Log.d("GODOT", "**PACK** - Path " + expansion_pack_path);

        if (!f.exists()) {

          pack_valid = false;
          Log.d("GODOT", "**PACK** - File does not exist");

        } else if (obbIsCorrupted(expansion_pack_path, main_pack_md5)) {
          Log.d("GODOT", "**PACK** - Expansion pack (obb) is corrupted");
          pack_valid = false;
          try {
            f.delete();
          } catch (Exception e) {
            Log.d("GODOT", "**PACK** - Error deleting corrupted expansion pack (obb)");
          }
        }

        if (!pack_valid) {
          Log.d("GODOT", "Pack Invalid, try re-downloading.");

          Intent notifierIntent = new Intent(this, this.getClass());
          notifierIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);

          PendingIntent pendingIntent =
              PendingIntent.getActivity(this, 0, notifierIntent, PendingIntent.FLAG_UPDATE_CURRENT);

          int startResult;
          try {
            Log.d("GODOT", "INITIALIZING DOWNLOAD");
            startResult =
                DownloaderClientMarshaller.startDownloadServiceIfRequired(
                    getApplicationContext(), pendingIntent, GodotDownloaderService.class);
            Log.d("GODOT", "DOWNLOAD SERVICE FINISHED:" + startResult);

            if (startResult != DownloaderClientMarshaller.NO_DOWNLOAD_REQUIRED) {
              Log.d("GODOT", "DOWNLOAD REQUIRED");
              // This is where you do set up to display the download
              // progress (next step)
              mDownloaderClientStub =
                  DownloaderClientMarshaller.CreateStub(this, GodotDownloaderService.class);

              setContentView(com.godot.game.R.layout.downloading_expansion);
              mPB = (ProgressBar) findViewById(com.godot.game.R.id.progressBar);
              mStatusText = (TextView) findViewById(com.godot.game.R.id.statusText);
              mProgressFraction = (TextView) findViewById(com.godot.game.R.id.progressAsFraction);
              mProgressPercent = (TextView) findViewById(com.godot.game.R.id.progressAsPercentage);
              mAverageSpeed = (TextView) findViewById(com.godot.game.R.id.progressAverageSpeed);
              mTimeRemaining = (TextView) findViewById(com.godot.game.R.id.progressTimeRemaining);
              mDashboard = findViewById(com.godot.game.R.id.downloaderDashboard);
              mCellMessage = findViewById(com.godot.game.R.id.approveCellular);
              mPauseButton = (Button) findViewById(com.godot.game.R.id.pauseButton);
              mWiFiSettingsButton = (Button) findViewById(com.godot.game.R.id.wifiSettingsButton);

              return;
            } else {
              Log.d("GODOT", "NO DOWNLOAD REQUIRED");
            }
          } catch (NameNotFoundException e) {
            // TODO Auto-generated catch block
            Log.d("GODOT", "Error downloading expansion package:" + e.getMessage());
          }
        }
      }
    }

    initializeGodot();

    //	instanceSingleton( new GodotFacebook(this) );

  }