示例#1
0
  public void selectProfilePicture(Intent data) {

    Uri selectedImage = data.getData();

    try {

      Bitmap finalImage = ImageHandler.getPortraitImage(selectedImage, getActivity(), 300, 200);
      profilePicture.setImageBitmap(finalImage);

      Bitmap thumbNail = ImageHandler.getPortraitImage(selectedImage, getActivity(), 35, 23);

      // http://stackoverflow.com/questions/26292969/can-i-store-image-files-in-firebase-using-java-api
      ByteArrayOutputStream stream = new ByteArrayOutputStream();
      finalImage.compress(Bitmap.CompressFormat.PNG, 100, stream);
      String imageString = Base64.encodeToString(stream.toByteArray(), Base64.DEFAULT);

      stream.reset();
      thumbNail.compress(Bitmap.CompressFormat.PNG, 100, stream);
      String thumbNString = Base64.encodeToString(stream.toByteArray(), Base64.DEFAULT);

      MainActivity.getUser().setProfilePicture(imageString, stream.toByteArray());
      stream.close();

      new FbDataChange("/users/" + MainActivity.getUser().getUid() + "/profilePicture", imageString)
          .execute();

      new FbDataChange("/users/" + MainActivity.getUser().getUid() + "/profileThumb", thumbNString)
          .execute();
    } catch (IOException e) {
    }
  }
示例#2
0
  public void updateUI() {

    User u = MainActivity.getUser();

    if (userName == null || u == null) {

      return;
    }

    points.setText("Points: " + u.getPoints());
    level.setText("" + LevelPicker.levelPicker((int) u.getPoints()));
    userName.setText(MainActivity.getMeRequest().getMe().getFirstName());

    byte[] profilePictureArray = u.getInAppProfilePicture();

    if (profilePictureArray != null) {

      profilePicture.setImageBitmap(
          BitmapFactory.decodeByteArray(profilePictureArray, 0, profilePictureArray.length));

    } else {
      profilePicture.setImageDrawable(getResources().getDrawable(R.drawable.ic_mood_24dp));
    }

    if (MainActivity.getUserContentPreview() != null) {

      contentPicture.setImageBitmap(MainActivity.getUserContentPreview());

    } else {

      contentPicture.setImageDrawable(getResources().getDrawable(R.drawable.ic_assignment_24dp));
    }
  }
示例#3
0
  public static void slideDownRoutesListView() {
    final MainActivity mainActivity = _getMainActivity();
    if (mainActivity == null) {
      return;
    }
    final Model model = _getModel();

    LinearLayout listViewAndProgressBarLinearLayout =
        (LinearLayout) mainActivity.findViewById(R.id.listViewAndProgressBarLinearLayout);
    TranslateAnimation animation = null;
    if (model.getFavorite().size() == 1) {
      animation = new TranslateAnimation(0, 0, 0, model.dpToPx(60));
      mainActivity.getLeftMenu().getTicketsTray().setVisibility(View.GONE);
    }
    if (animation != null) {
      animation.setDuration(Animations.ANIMATION_DURATION);
      animation.setAnimationListener(
          new AnimationListener() {

            @Override
            public void onAnimationStart(Animation animation) {}

            @Override
            public void onAnimationRepeat(Animation animation) {}

            @Override
            public void onAnimationEnd(Animation animation) {
              mainActivity.getLeftMenu().getTicketsTray().update();
            }
          });
      listViewAndProgressBarLinearLayout.startAnimation(animation);
    }
  }
 public FallbackLocationTracker(MainActivity context) throws Exception {
   boolean gps_worked = true;
   boolean net_worked = true;
   try {
     gps =
         new ProviderLocationTracker(
             context,
             ProviderLocationTracker.ProviderType.GPS,
             (IVossenJachtApp) context.getApplication());
   } catch (Exception e) {
     // context.
     gps_worked = false;
   }
   try {
     net =
         new ProviderLocationTracker(
             context,
             ProviderLocationTracker.ProviderType.NETWORK,
             (IVossenJachtApp) context.getApplication());
   } catch (Exception e) {
     net_worked = false;
   }
   if (!gps_worked && !net_worked) {
     throw new Exception("Both location services not working.");
   }
 }
  private void doNativeLogin(String email, final String password) {
    if (email.equals("") || password.equals("")) {
      SPiDLogger.log("Missing email and/or password");
      Toast.makeText(getActivity(), "Missing email and/or password", Toast.LENGTH_LONG).show();
    } else {
      SPiDLogger.log("Email: " + email + " password: "******"Received error: " + exception.getMessage());
                  Toast.makeText(
                          getActivity(),
                          "Received error: " + exception.getMessage(),
                          Toast.LENGTH_LONG)
                      .show();
                }
              });
      tokenRequest.execute();
    }
  }
      /** If the update was successful restart the MainActivity */
      @Override
      protected void onPostExecute(String result) {
        super.onPostExecute(result);

        progr_dlg.dismiss();

        // After all the update is (succesfully) done we have to restart
        // the main activity

        if (DONE.equals(result)) {
          // either we were started tru intent (return to main)
          if (context instanceof PreferencesActivity) {
            Activity a = (Activity) context;
            a.setResult(PreferencesActivity.RESULT_DATA_UPDATED);
            // this will call on activity result
            a.finish();
          }

          // or directly by passing context: restart directly
          if (context instanceof MainActivity) {
            MainActivity mainActivity = (MainActivity) context;
            mainActivity.restartActivity(0);
          }
        }
      }
  @Override
  public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    final ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
      actionBar.setDisplayHomeAsUpEnabled(true);
    }

    // set language
    MainActivity.setLocale(this);
    setContentView(R.layout.dbresult);

    // force media volume controls
    setVolumeControlStream(AudioManager.STREAM_MUSIC);

    setupList();

    QueryArgs queryArgs = ListFragment.lameStatic.queryArgs;
    MainActivity.info("queryArgs: " + queryArgs);
    final TextView tv = (TextView) findViewById(R.id.dbstatus);

    if (queryArgs != null) {
      tv.setText(getString(R.string.status_working) + "...");
      Address address = queryArgs.getAddress();
      LatLng center = MappingFragment.DEFAULT_POINT;
      if (address != null) {
        center = new LatLng(address.getLatitude(), address.getLongitude());
      }
      setupMap(center, savedInstanceState);
      setupQuery(queryArgs);
    } else {
      tv.setText(getString(R.string.status_fail) + "...");
    }
  }
  public OnlineGameController(
      int size, TextView tileViews[][], MainActivity main, boolean host, boolean online) {
    // constructor
    rnd = new Random();
    this.size = size;
    grid = new Grid(size);
    this.tileViews = tileViews;
    this.main = main;
    this.host = this.myTurn = host;
    main.score = 0;
    main.updateScore();

    tiles = new ArrayList<Tile>() {};

    minorXComparator = new MinorXComparator();
    minorYComparator = new MinorYComparator();
    majorXComparator = new MajorXComparator();
    majorYComparator = new MajorYComparator();

    if (host) {
      addRandomTile();
      addRandomTile();

      if (online) {}
    }
  }
示例#9
0
  public void save(View view) {
    EditText t = (EditText) findViewById(R.id.text_box);
    EditText s = (EditText) findViewById(R.id.subtext_box);

    if (t.getText().toString().trim().equals("")) {
      Toast.makeText(this, "No Title Entered!", Toast.LENGTH_LONG).show();
      return;
    }
    if (t.getText().toString().contains(StorageHandler.TOKEN)
        || s.getText().toString().contains(StorageHandler.TOKEN)) {
      Toast.makeText(
              this,
              "You may not include \""
                  + StorageHandler.TOKEN
                  + "\" in either Title, or Additional Information",
              Toast.LENGTH_LONG)
          .show();
      return;
    }

    if (position != -1) {
      MainActivity.set(new ListItem(t.getText().toString(), s.getText().toString()), position);
    } else MainActivity.add(new ListItem(t.getText().toString(), s.getText().toString()));
    finish();
  }
  public void onClick(View v) {

    Log.v(TAG, "onClick" + v.getTag());
    String[] params = (String[]) v.getTag();
    Long babyId = Long.parseLong(params[0]);
    String babyName = params[1];

    switch (v.getId()) {
      case R.id.baby_select:
        MainActivity.ACTIVE_BABY_ID = babyId;
        MainActivity.ACTIVE_BABY_NAME = babyName;
        ((MainActivity) context)
            .handleFragments(
                new ActivitiesFragment(), ActivitiesFragment.TAG, ActivitiesFragment.KEEP_IN_STACK);
        break;
      case R.id.baby_edit:
        MainActivity.ACTIVE_BABY_ID = babyId;
        ((MainActivity) context)
            .handleFragments(
                new BabyProfileFragment(),
                BabyProfileFragment.TAG,
                BabyProfileFragment.KEEP_IN_STACK);
        break;
    }
  }
示例#11
0
  @Override
  protected void onPostExecute(RefreshListResult result) {
    if (result != null) {
      if (result.getWhatList().equals("getList")) { // if the command was getList
        ListView lv =
            (ListView)
                mainActivity.findViewById(
                    R.id.files_listview); // find the view containing the songs
        SongAdapter aa =
            new SongAdapter(
                mainActivity,
                R.layout.playlist_song,
                result.getList()); // create a personnalised apdaptor to display song list
        lv.setAdapter(aa);
        mainActivity.setSongs(result.getList()); // add songs to the view

        // On démarre la socket pour écouter le serveur
        // on est sûr que le serveur est démarré et prêt
        new ListenerThread(mainActivity).execute();

        // on actualise la playlist
        Utils.getXML("getPlayList", mainActivity.getConnMgr(), mainActivity);
      } else if (result.getWhatList().equals("getPlayList")) { // if the command was getPLaylist
        ListView lv = (ListView) mainActivity.findViewById(R.id.playlist_listview);
        SongAdapter aa = new SongAdapter(mainActivity, R.layout.playlist_song, result.getList());
        lv.setAdapter(aa);
        mainActivity.setPlaylist(result.getList());
      }
    }
  }
示例#12
0
 @Override
 public void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.main);
   Intent intent = getIntent();
   Uri uri = intent.getData();
   if (uri != null) {
     MainActivity.addLink(this, uri.toString());
     Uri newUri = Uri.parse("view-source:" + uri.toString());
     startChrome(newUri);
   }
   if (Intent.ACTION_SEND.equals(intent.getAction())) {
     Bundle extras = intent.getExtras();
     if (extras != null) {
       String text = extras.getString(Intent.EXTRA_TEXT);
       Pattern pattern = Pattern.compile(URL_PATTERN);
       if (text != null) {
         Matcher m = pattern.matcher(text);
         if (m.find()) {
           String url = m.group(1);
           MainActivity.addLink(this, url);
           Uri newUri = Uri.parse("view-source:" + url);
           startChrome(newUri);
         }
       }
     }
   }
   this.finish();
 }
示例#13
0
 @Before
 public void setUp() {
   MainActivity mainActivity = Robolectric.buildActivity(MainActivity.class).create().get();
   assertNotNull("Main Activity not setup", mainActivity);
   listView = (ListView) mainActivity.findViewById(R.id.list_of_signs);
   zodiacSigns =
       RuntimeEnvironment.application.getResources().getStringArray(R.array.zodiac_array);
 }
示例#14
0
  // the meat of switching the above fragment
  private void switchFragment(SherlockFragment fragment) {
    if (getActivity() == null) return;

    if (getActivity() instanceof MainActivity) {
      MainActivity ra = (MainActivity) getActivity();
      ra.switchContent(fragment);
    }
  }
  // Should fail
  @Test
  public void testButtonThree_shouldChangeText() {
    MainActivity activity = Robolectric.setupActivity(MainActivity.class);
    activity.findViewById(R.id.button_3).performClick();

    TextView textView = (TextView) activity.findViewById(R.id.test_text);
    Assert.assertTrue("Button 3 Clicked".equals(textView.getText()));
  }
示例#16
0
 @SuppressLint("NewApi")
 public void mid(View view) {
   EditText editX1 = (EditText) findViewById(R.id.editMidX1);
   EditText editY1 = (EditText) findViewById(R.id.editMidY1);
   EditText editX2 = (EditText) findViewById(R.id.editMidX2);
   EditText editY2 = (EditText) findViewById(R.id.editMidY2);
   if (!MainActivity.Empty(editX1)
       && !MainActivity.Empty(editY1)
       && !MainActivity.Empty(editX2)
       && !MainActivity.Empty(editY2)) {
     double X1 = Double.parseDouble(editX1.getText().toString());
     double Y1 = Double.parseDouble(editY1.getText().toString());
     double X2 = Double.parseDouble(editX2.getText().toString());
     double Y2 = Double.parseDouble(editY2.getText().toString());
     if (X1 == X2 && Y1 == Y2) {
       TextView res = (TextView) findViewById(R.id.textMidRes);
       res.setText("Enter valid points");
     } else {
       TextView res = (TextView) findViewById(R.id.textMidRes);
       double resX = ((X1 + X2) / 2);
       double resY = ((Y1 + Y2) / 2);
       if (resX == (int) resX && resY == (int) resY) {
         res.setText(
             "The midpoint of this line is ("
                 + String.valueOf((int) resX)
                 + ","
                 + String.valueOf((int) resY)
                 + ")");
       } else {
         if (resX == (int) resX) {
           res.setText(
               "The midpoint of this line is ("
                   + String.valueOf((int) resX)
                   + ","
                   + String.valueOf(resY)
                   + ")");
         }
         if (resY == (int) resY) {
           res.setText(
               "The midpoint of this line is ("
                   + String.valueOf(resX)
                   + ","
                   + String.valueOf((int) resY)
                   + ")");
         }
         if (resX != (int) resX && resY != (int) resY) {
           res.setText(
               "The midpoint of this line is ("
                   + String.valueOf(resX)
                   + ","
                   + String.valueOf(resY)
                   + ")");
         }
       }
     }
   }
 }
示例#17
0
 private void displayDialog(View v, boolean isCancelable) {
   if (mContext.CommonDialog == null)
     mContext.CommonDialog = new AlertDialog.Builder(mContext).show();
   else mContext.CommonDialog.show();
   mContext.CommonDialog.setContentView(v);
   Typeface font = Typeface.createFromAsset(mContext.getAssets(), "fonts/hurry up.ttf");
   SetFontToControls(font, (ViewGroup) v);
   mContext.CommonDialog.setCancelable(isCancelable);
 }
示例#18
0
  @Override
  public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    fContext = getActivity().getApplicationContext();
    mActivity = (MainActivity) getActivity();
    //        bottomPanel = (LinearLayout) rootView.findViewById(R.id.bottomPanelPhoto);
    progress = (DonutProgress) rootView.findViewById(R.id.donut_progress);
    progress.setVisibility(View.GONE);
    btnSave = (ActionButton) rootView.findViewById(R.id.aBtnSave);

    btnSave.setImageResource(R.drawable.ic_check);
    btnSave.setButtonColor(Color.TRANSPARENT);
    btnSave.setStrokeColor(Color.GREEN);
    btnSave.setStrokeWidth(3.0f);
    btnSave.setButtonColorPressed(Color.LTGRAY);
    btnSave.removeShadow();
    btnSave.setType(ActionButton.Type.BIG);
    btnSave.setShowAnimation(ActionButton.Animations.FADE_IN);
    btnSave.setHideAnimation(ActionButton.Animations.FADE_OUT);
    btnSave.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            new SendFilesTask().execute();
          }
        });
    btnCancel = (ActionButton) rootView.findViewById(R.id.aBtnBack);
    btnCancel.setImageResource(R.drawable.ic_cancel);
    btnCancel.setButtonColor(Color.TRANSPARENT);
    btnCancel.setStrokeColor(Color.RED);
    btnCancel.setStrokeWidth(3.0f);
    btnCancel.setButtonColorPressed(Color.LTGRAY);
    btnCancel.removeShadow();
    btnCancel.setType(ActionButton.Type.BIG);
    btnCancel.setShowAnimation(ActionButton.Animations.FADE_IN);
    btnCancel.setHideAnimation(ActionButton.Animations.FADE_OUT);
    btnCancel.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            btnCancel.playHideAnimation();
            btnSave.playHideAnimation();
            mActivity.onBackPressed();
          }
        });
    imgView = (ImageView) rootView.findViewById(R.id.imgView);
    try {
      ImageLoader.getInstance().displayImage("file:///mnt/" + bmp, imgView);
    } catch (Exception e) {

    }
    mActivity.setIsFAB(false);
    mActivity.updateFAB();
    if (savedInstanceState == null) {
      startAnimation();
    }
  }
示例#19
0
  private void doSearch(String query) {
    MainActivity ma = (MainActivity) getActivity();
    RoomManager rm = (RoomManager) ma.getRoomManager();

    SingleRoom sr = rm.findRoomByName(query);
    if (sr != null) {
      ma.setTargetRoom(sr);
      ma.changeFragment(new Room());
    }
  }
  @Override
  protected void setUp() throws Exception {
    super.setUp();
    final MainActivity a = getActivity();
    // ensure a valid handle to the activity has been returned
    assertNotNull(a);

    mTextView1 = (TextView) a.findViewById(R.id.lib_text1);
    mTextView2 = (TextView) a.findViewById(R.id.lib_text2);
  }
示例#21
0
 /** * 设置浮窗权限 */
 public void setDrawOverlays() {
   if (VersionUtil.isM()) {
     MainActivity mainActivity = (MainActivity) mMainMediator;
     Intent intent =
         new Intent(
             Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
             Uri.parse("package:" + mainActivity.getPackageName()));
     mainActivity.startActivityForResult(intent, Constants.OVERLAY_PERMISSION_REQ_CODE);
   }
 }
示例#22
0
  @Test
  public void check_drawer_menu_settings_item() throws Exception {
    MainActivity activity = Robolectric.buildActivity(MainActivity.class).create().get();

    activity.onNavigationDrawerItemSelected(NavigationDrawerFragment.ITEM_SETTINGS);
    if (BuildConfig.DEBUG
        && !(activity.getSupportFragmentManager().findFragmentById(R.id.page_container)
            instanceof SettingsFragment)) {
      throw new AssertionError();
    }
  }
 public void DeregisterSuccess() {
   Log.i(TAG, "deregistering success");
   this.deregisterTimer.cancel();
   t.interrupt();
   client.isThreadStopped = true;
   client.Destroy();
   uiUpdate.makeToastNotification("Deregister success!");
   uiUpdate.updateUserStatus("offline");
   uiUpdate.clearContactsAndGroups();
   this.Initiate_Fsm.invokeFSM(FSMEVENTS.Deregister_Success);
 }
  @Test
  public void testButtonAction() {
    Button button = (Button) activity.findViewById(R.id.button);
    assertEquals(button.getVisibility(), View.VISIBLE);
    assertNotNull("button is null", button);
    button.performClick();

    textView = (TextView) activity.findViewById(R.id.section_label);
    assertEquals(textView.getVisibility(), View.VISIBLE);
    assertEquals("Fragment 3", textView.getText().toString());
  }
 /**
  * Called when a shared preference is changed, added, or removed. This may be called even if a
  * preference is set to its existing value.
  *
  * <p>
  *
  * <p>This callback will be run on your main thread.
  *
  * @param sharedPreferences The {@link SharedPreferences} that received the change.
  * @param key The key of the preference that was changed, added, or
  */
 @Override
 public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
   if (key.equals("Refresh_Network")) {
     if (MainActivity.getInstance() != null) MainActivity.getInstance().checkNetwork();
   } else if (key.equals("Connection_Host")) {
     m_connectionHost.setText(
         sharedPreferences.getString("Connection_Host", m_connectionHost.getText()));
   } else if (key.equals("Connection_Port")) {
     m_connectionPort.setText(
         sharedPreferences.getString("Connection_Port", m_connectionPort.getText()));
   }
 }
示例#26
0
 public void upgrade(int count) {
   if ((count % 5 == 0) && (count <= 85)) {
     int n = (count / 5);
     status = statuses[n];
     MainActivity.setStatusText("You are the " + status);
     awards.add(0, status);
   } else if (count == 95) {
     status = statuses[19];
     MainActivity.setStatusText("YOU ARE THE LEGENDARY" + status);
     awards.add(0, status);
   }
 }
  @Override
  protected void setUp() throws Exception {
    super.setUp();
    final MainActivity a = getActivity();
    // ensure a valid handle to the activity has been returned
    assertNotNull(a);

    mResOverLay = (TextView) a.findViewById(R.id.resoverlay);
    mResOverLay1 = (TextView) a.findViewById(R.id.resoverlay1);
    mBuildConfig1 = (TextView) a.findViewById(R.id.buildconfig1);
    mCodeOverlay1 = (TextView) a.findViewById(R.id.codeoverlay1);
  }
  // Should pass
  @Test
  public void testButtonOneClick_shouldShowToast() {
    MainActivity activity = Robolectric.setupActivity(MainActivity.class);
    activity.findViewById(R.id.button_1).performClick();

    ShadowLooper.idleMainLooper();
    // Check toast correctness
    Assert.assertTrue(ShadowToast.getTextOfLatestToast().equals("Button #1 Clicked"));

    // Check textView text
    TextView textView = (TextView) activity.findViewById(R.id.test_text);
    Assert.assertTrue("Button 1 Clicked".equals(textView.getText()));
  }
示例#29
0
 protected final void setExplorerMode(final boolean explorerMode) {
   MainActivity act = (MainActivity) getActivity();
   if (act == null) return;
   PreferenceManager.getDefaultSharedPreferences(act)
       .edit()
       .putBoolean("explorer_mode", explorerMode)
       .commit();
   reload();
   act.getFragmentManager().popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
   act.setTitle(mPresenter.getTitle());
   act.invalidateOptionsMenu();
   act.invalidateCrumbs();
 }
  /**
   * Set the current state of the chat connection
   *
   * @param state An integer defining the current connection state
   */
  private synchronized void setState(int state) {
    if (D)
      Log.d(
          TAG,
          "setState(): from "
              + MainActivity.TranslateState(mState)
              + " to "
              + MainActivity.TranslateState(state));
    mState = state;

    // Give the new state to the Handler so the UI Activity can update
    mHandler.obtainMessage(MainActivity.MESSAGE_STATE_CHANGE, state, -1).sendToTarget();
  }