コード例 #1
0
  private boolean connect(View view) {
    if (D) Log.d(TAG, "Establishing connection to: " + btDevice.getName());

    try {
      btSocket = btDevice.createRfcommSocketToServiceRecord(SPP_UUID);
      btSocket.connect();
      Toast.makeText(this, "Connected to: " + btDevice.getName(), Toast.LENGTH_LONG).show();
      return true;
    } catch (IOException e) {
      Toast.makeText(this, "Failed to connect to: " + btDevice.getName(), Toast.LENGTH_LONG).show();
      Log.e(TAG, e.getLocalizedMessage());
    }
    return false;
  }
コード例 #2
0
ファイル: AndroidCallUtil.java プロジェクト: gaixiaochuan/BIM
  /**
   * Checks if there is a call in progress. If true then shows a warning toast and finishes the
   * activity.
   *
   * @param activity activity doing a check.
   * @return <tt>true</tt> if there is call in progress and <tt>Activity</tt> was finished.
   */
  public static boolean checkCallInProgress(Activity activity) {
    if (CallManager.getActiveCallsCount() > 0) {
      logger.warn("Call is in progress");

      Toast t =
          Toast.makeText(activity, R.string.service_gui_WARN_CALL_IN_PROGRESS, Toast.LENGTH_SHORT);
      t.show();

      activity.finish();
      return true;
    } else {
      return false;
    }
  }
コード例 #3
0
 public void run() {
   try {
     while (!Thread.interrupted()) {
       // Blocks until next piece of toast is available:
       Toast t = dryQueue.take();
       t.butter();
       print(t);
       butteredQueue.put(t);
     }
   } catch (InterruptedException e) {
     print("Butterer interrupted");
   }
   print("Butterer off");
 }
コード例 #4
0
  @Override
  protected void onStart() {
    final GameBoard boardView = (GameBoard) this.findViewById(R.id.gameBoard);
    SharedPreferences prefs = getPreferences(Context.MODE_PRIVATE);

    this.level = prefs.getInt("level", 0);
    String mapJson = prefs.getString("map", null);

    if (mapJson == null) {
      waitForNext = true;
    } else {
      this.game.initGame(mapJson);
      String howdyPosition = prefs.getString("howdy", null);

      if (howdyPosition != null) {
        this.game.setHowdyPosition(howdyPosition);
      }

      Toast.makeText(this, this.level + "", Toast.LENGTH_SHORT).show();
    }

    String allDoneLevelsString = prefs.getString("doneLevels", null);

    if (allDoneLevelsString != null) {
      allDoneLevels = new ArrayList<String>(Arrays.asList(allDoneLevelsString.split(",")));
    }

    super.onStart();
  }
コード例 #5
0
 public void run() {
   try {
     while (!Thread.interrupted()) {
       // Blocks until next piece of toast is available:
       Toast t = finishedQueue.take();
       // Verify that the toast is coming in order,
       // and that all pieces are getting jammed:
       if (t.getId() != counter++ || t.getStatus() != Toast.Status.JAMMED) {
         print(">>>> Error: " + t);
         System.exit(1);
       } else print("Chomp! " + t);
     }
   } catch (InterruptedException e) {
     print("Eater interrupted");
   }
   print("Eater off");
 }
コード例 #6
0
 private void saveOrder(Order orderToSave) {
   valueList.put("_id", currentOrder.getOrderId());
   for (EditText fieldToSave : editFields) {
     if (fieldToSave.getText() != null) {
       valueList.put(fieldToSave.getTag().toString(), fieldToSave.getText().toString());
     }
   }
   orderToSave.setOrderValues(valueList);
   if (orderToSave.save()) {
     Toast toast =
         Toast.makeText(
             MainActivity.appContext,
             "Order " + orderToSave.getOrderId() + " saved",
             Toast.LENGTH_LONG);
     toast.show();
   }
 }
コード例 #7
0
 private void doIntentCityManager() {
   if (WeatherData.getCityInfo(Gl.getCurrentCityIndex()).mShowType
       == com.moji.mjweather.data.CityWeatherInfo.ShowType.ST_UPDATING) {
     Toast.makeText(this, 0x7f0b0041, 0).show();
   } else {
     Gl.setChangedCity(false);
     startActivityForResult(new Intent(this, CityManagerActivity.class), 99);
   }
 }
コード例 #8
0
 @Override
 public void onInvalidDateSelected(Date date) {
   String errMessage =
       getResources()
           .getString(
               R.string.invalid_date,
               fullDateFormat.format(minCal.getTime()),
               fullDateFormat.format(maxCal.getTime()));
   Toast.makeText(getContext(), errMessage, Toast.LENGTH_SHORT).show();
 }
コード例 #9
0
 private boolean disconnect(View view) {
   try {
     btSocket.close();
     Toast.makeText(this, "Disconnected from: " + btDevice.getName(), Toast.LENGTH_LONG).show();
     return true;
   } catch (IOException e) {
     Log.e(TAG, e.getLocalizedMessage());
   }
   return false;
 }
コード例 #10
0
 private void forFirstRun() {
   if (Gl.getIsFirstRun()) {
     if (!Gl.getAdON()) StatsService.checkAdSwitchAsync();
     StatsUtil.setNextSendTime(false);
     if (PlayerUtil.isDataExpired()) {
       FileUtil.delFile(PlayerUtil.TTS_DATA_BG_PATH);
       Toast.makeText(Gl.Ct(), 0x7f0b0221, 1).show();
     }
   }
 }
コード例 #11
0
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    // Get local Bluetooth adapter
    mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

    // If the adapter is null, then Bluetooth is not supported
    if (mBluetoothAdapter == null) {
      Toast.makeText(this, "Bluetooth is not available", Toast.LENGTH_LONG).show();
      finish();
      return;
    }

    ImageView controlsView = (ImageView) findViewById(R.id.controlsView);
    controlsView.setOnTouchListener(new ControlsTouchListener());
  }
コード例 #12
0
 private void cancelUpdateWeather(CityWeatherInfo cityweatherinfo, boolean flag) {
   if (cityweatherinfo == null)
     cityweatherinfo = WeatherData.getCityInfo(Gl.getCurrentCityIndex());
   mUpdateWeather.setImageResource(0x7f02014e);
   isUpdating = false;
   Gl.setIsLocationbyGPS(false);
   if (mWeatherUpdater != null) mWeatherUpdater.cancel();
   if (mUpdateCallbackImpl != null)
     WeatherPublisher.getInstance().unSubscribe(mUpdateCallbackImpl);
   mUpdateLayout.setVisibility(8);
   if (mPublicTextView != null) mPublicTextView.setVisibility(0);
   if (cityweatherinfo.mShowType == com.moji.mjweather.data.CityWeatherInfo.ShowType.ST_UPDATING)
     if (cityweatherinfo.m_lastUpdateTime.length() <= 0)
       cityweatherinfo.mShowType =
           com.moji.mjweather.data.CityWeatherInfo.ShowType.ST_NEED_BE_UPDATE;
     else cityweatherinfo.mShowType = com.moji.mjweather.data.CityWeatherInfo.ShowType.ST_OK;
   if (flag) Toast.makeText(this, 0x7f0b0039, 0).show();
 }
コード例 #13
0
 private void gotoBookmark(Bookmark bookmark) {
   bookmark.onOpen();
   final FBReader fbreader = (FBReader) FBReader.Instance();
   final long bookId = bookmark.getBookId();
   if ((fbreader.Model == null) || (fbreader.Model.Book.getId() != bookId)) {
     final Book book = Book.getById(bookId);
     if (book != null) {
       finish();
       fbreader.openBook(book, bookmark);
     } else {
       Toast.makeText(
               this,
               ZLResource.resource("errorMessage").getResource("cannotOpenBook").getValue(),
               Toast.LENGTH_SHORT)
           .show();
     }
   } else {
     finish();
     fbreader.gotoBookmark(bookmark);
   }
 }
コード例 #14
0
  private void selectItem(int index) {
    _info = mInfoList.get(index);
    if (!(new File(_info.archiveFile)).exists()) {
      String text =
          String.format(
              Locale.ENGLISH,
              "Location '%s' cannot be selected!\n" + "Please, download location first!",
              _info.title);
      Toast.makeText(mContext, text, Toast.LENGTH_LONG).show();
      return;
    }

    AlertDialog.Builder alertBuilder = new AlertDialog.Builder(mContext);
    alertBuilder.setTitle(String.format(Locale.ENGLISH, "Location '%s'", _info.title));

    alertBuilder.setNegativeButton(
        "Delete location",
        new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dlg, int id) {
            deleteLocation(_info);
          }
        });
    alertBuilder.setPositiveButton(
        "Select location",
        new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dlg, int id) {
            selectLocation(_info);
          }
        });

    AlertDialog dialog = alertBuilder.create();
    dialog.setCanceledOnTouchOutside(false);
    dialog.show();
  }
コード例 #15
0
  public void tryLogin() {
    mName = mEtAccount.getText().toString();
    mPassword = mEtPassword.getText().toString();

    if (mName.equals("") || mPassword.length() < 5) { // Please Specify Your Name and Sex"
      Toast.makeText(
              MainActivity.this,
              "Please Specify Your Name and Password correctly",
              Toast.LENGTH_LONG)
          .show();
    } else {
      mUserInfo = new UserInfo(mName, 0, 0, 0, 0, 0, 0);

      /*  if mNetcon is connected already, close it first  */
      /*  here we use try because mNetCon might not have been instantiated yet  */
      /*			try {
      				NetConnect.getnetConnect().closeNetConnect();
      			} catch (Exception e) {}
      			try {
      				InitData.closeInitData();
      				FriendListInfo.closeFriendListInfo();
      				ChatServiceData.closeChatServiceData();
      			} catch (Exception e) {}
      */
      CloseAll.closeAll();
      /*  to establish a new connect  */

      NetworkService.getInstance().onInit(this);
      NetworkService.getInstance().setupConnection();
      if (NetworkService.getInstance().getIsConnected()) {
        String usrInfo =
            mUserInfo.toString()
                + GlobalStrings.signinDivider
                + mPassword
                + GlobalStrings.signinDivider;
        NetworkService.getInstance().sendUpload(GlobalMsgTypes.msgHandShake, usrInfo);
      } else {
        NetworkService.getInstance().closeConnection();
        Toast.makeText(this, "failed to connect to Server", Toast.LENGTH_LONG).show();
        return;
      }

      InitData initData = InitData.getInitData();
      initData.start();
      try {
        initData.join();
      } catch (Exception e) {
      }
      mUserInfo = initData.getUserInfo();

      Log.d(
          "connectedApp isonline : ",
          ""
              + mUserInfo.getIsOnline()
              + "+++++++++++++"
              + "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");

      if (mUserInfo.getId() < 0) {
        Toast.makeText(this, "invalid username or password", Toast.LENGTH_SHORT).show();
        return;
      }

      Log.d(
          "connectedApp isonline : ",
          ""
              + mUserInfo.getIsOnline()
              + "+++++++++++++"
              + "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");

      ConnectedApp connected_app0 = ConnectedApp.getInstance();
      //		    connected_app0.setConnect(mNetCon);
      connected_app0.setUserInfo(mUserInfo);
      connected_app0.clearListActivity();
      connected_app0.instantiateListActivity();

      Intent intent0 = new Intent(MainActivity.this, MainBodyActivity.class);
      //			intent0.putExtra("username", mUserInfo.getName());
      //			intent0.putExtra("usersex", mUserInfo.getSex());
      startActivity(intent0);

      finish();
    }
  }
コード例 #16
0
  public void nextLevel() {
    boolean loaded = false;
    final GameBoard boardView = (GameBoard) this.findViewById(R.id.gameBoard);
    this.level++;

    AssetManager am = getResources().getAssets();

    try {
      List<String> allTutoLevels =
          new LinkedList<String>(Arrays.asList(am.list("levels/tutorial")));

      // if(addMsg){
      //    allTutoLevels.addAll(Arrays.asList(am.list("msg")));
      // }

      Log.d(TAG, allTutoLevels.toString());

      for (String name : allTutoLevels) {
        if (name.startsWith(this.level + ".")) {
          BufferedReader br =
              new BufferedReader(new InputStreamReader(am.open("levels/tutorial/" + name)));
          String line;
          String levelJSON = "";

          while ((line = br.readLine()) != null) {
            levelJSON += line + "\n";
          }

          br.close();

          game.initGame(
              levelJSON, boardView.getMeasuredWidth() / 60, boardView.getMeasuredHeight() / 60);
          loaded = true;
        }
      }
    } catch (IOException e) {
      e.printStackTrace();
    }

    if (!loaded) {
      Random r = new Random();

      List<String> allLevels = new ArrayList<>();

      try {
        allLevels = Arrays.asList(am.list("levels"));
      } catch (IOException e) {
      }

      if (r.nextBoolean() && !allLevels.isEmpty() && allLevels.size() != allDoneLevels.size()) {
        try {
          int nLevel;
          do {
            nLevel = r.nextInt(allLevels.size());
          } while (allDoneLevels.contains(allLevels.get(nLevel)));

          String name = allLevels.get(nLevel);
          BufferedReader br = new BufferedReader(new InputStreamReader(am.open("levels/" + name)));

          String line;
          String levelJSON = "";

          while ((line = br.readLine()) != null) {
            levelJSON += line + "\n";
          }

          br.close();

          allDoneLevels.add(name);

          game.initGame(
              levelJSON, boardView.getMeasuredWidth() / 60, boardView.getMeasuredHeight() / 60);
        } catch (IOException e) {
          this.game.initGame(
              level, boardView.getMeasuredWidth() / 60, boardView.getMeasuredHeight() / 60);
        }
      } else {
        this.game.initGame(
            level, boardView.getMeasuredWidth() / 60, boardView.getMeasuredHeight() / 60);
      }
    }

    // am.close();

    boardView.setGame(this.game);
    boardView.invalidate();
    boardView.getHowdyShadeView().invalidate();

    Toast.makeText(this, this.level + "", Toast.LENGTH_SHORT).show();

    Log.i(
        TAG,
        "Max tiles : "
            + (boardView.getMeasuredWidth() / 60) * (boardView.getMeasuredHeight() / 60));
  }