@Override
  protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    //
    //	this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.main_login);

    mEtAccount = (EditText) findViewById(R.id.mainLoginEditAccount);
    mEtPassword = (EditText) findViewById(R.id.mainLoginEditPassword);
    mBtnLogin = (Button) findViewById(R.id.mainLoginBtn);
    mBtnRegister = (Button) findViewById(R.id.main_btn_register);

    /* this is to render the password edittext font to be default */
    mEtPassword.setTypeface(Typeface.DEFAULT);
    mEtPassword.setTransformationMethod(new PasswordTransformationMethod());

    mBtnLogin.setOnClickListener(
        new OnClickListener() {
          public void onClick(View v) {
            MainActivity.this.tryLogin();
          }
        });

    mBtnRegister.setOnClickListener(
        new OnClickListener() {
          public void onClick(View v) {
            Intent intent0 = new Intent(MainActivity.this, RegisterActivity.class);
            startActivity(intent0);
          }
        });
  }
Exemplo n.º 2
0
  private void showUserHashDialog() {
    String userHash = NavigineApp.Settings.getString("user_hash", "");

    LayoutInflater inflater = getLayoutInflater();
    View view = inflater.inflate(R.layout.user_hash_dialog, null);
    _userEdit = (EditText) view.findViewById(R.id.user_hash_edit);
    _userEdit.setText(userHash);
    _userEdit.setTypeface(Typeface.MONOSPACE);
    // _userEdit.addTextChangedListener(new TextWatcher()
    //  {
    //    public void afterTextChanged(Editable s) { }
    //    public void beforeTextChanged(CharSequence s, int start, int count, int after) { }
    //    public void onTextChanged(CharSequence s, int start, int before, int count)
    //    {
    //      String text = _userEdit.getText().toString();
    //      int length  = _userEdit.getText().length();
    //
    //      if (text.endsWith("-"))
    //        return;
    //
    //      if (count <= before)
    //        return;
    //
    //      if (length == 4 || length == 9 || length == 14)
    //      {
    //        _userEdit.setText((text + "-"));
    //        _userEdit.setSelection(length + 1);
    //      }
    //    }
    //  });

    AlertDialog.Builder alertBuilder = new AlertDialog.Builder(mContext);
    alertBuilder.setView(view);
    alertBuilder.setTitle("Enter user ID");
    alertBuilder.setNegativeButton(
        getString(R.string.cancel_button),
        new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dlg, int id) {}
        });

    alertBuilder.setPositiveButton(
        getString(R.string.ok_button),
        new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dlg, int id) {
            String userHash = _userEdit.getText().toString();
            SharedPreferences.Editor editor = NavigineApp.Settings.edit();
            editor.putString("user_hash", userHash);
            editor.commit();
            NavigineApp.applySettings();
            refreshMapList();
          }
        });

    AlertDialog dialog = alertBuilder.create();
    dialog.setCanceledOnTouchOutside(false);
    dialog.show();
  }
Exemplo n.º 3
0
 @Override
 public void onItemClick(AdapterView adapterView, View view, int position, long id) {
   Log.d(TAG, "onItemClick: position: " + position + ", id: " + id);
   String item = listAdapter.getItem(position).trim();
   if (item.endsWith(" =")) {
     item = item.substring(0, item.length() - 2);
   }
   if (!item.startsWith("no result")) {
     inputView.append(item);
   }
 }
Exemplo n.º 4
0
  @Override
  public boolean onEditorAction(TextView textView, int actionId, KeyEvent keyEvent) {
    Log.d(TAG, "onEditorAction: actionId: " + actionId + ", keyEvent: " + keyEvent);

    if ((actionId == EditorInfo.IME_ACTION_DONE)
        || ((keyEvent != null) && (keyEvent.getKeyCode() == KeyEvent.KEYCODE_ENTER))) {
      Log.d(TAG, "onEditorAction: IME_ACTION_DONE || KEYCODE_ENTER");
      String input = textView.getText().toString().trim();

      if (input.length() > 0) {
        String result = "";

        try {
          result += calculator.calculate(input);
        } catch (Exception e) {
          result = "no result (" + e.getMessage() + ")";
        }

        if (listAdapter.getCount() > 0) {
          listAdapter.add("");
        }

        listAdapter.add(input + " =");
        if (input.indexOf("@") > -1) {
          listAdapter.add(calculator.getEquation() + " =");
        }
        listAdapter.add(result);
        listAdapter.notifyDataSetChanged();

        inputView.endBatchEdit();
        inputView.setText("");
        hideKeyboard();
      }
    }

    return false;
  }
Exemplo n.º 5
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    Log.d(TAG, "onCreate");
    super.onCreate(savedInstanceState);
    Thread.currentThread().setUncaughtExceptionHandler(this);
    setContentView(R.layout.main);

    inputView = (EditText) findViewById(R.id.input_view);
    inputView.setOnEditorActionListener(this);

    listAdapter = new ArrayAdapter<String>(this, R.layout.row);
    listAdapter.setNotifyOnChange(true);

    resultsView = (ListView) this.findViewById(R.id.results_view);
    resultsView.setAdapter(listAdapter);
    resultsView.setOnItemClickListener(this);
  }
  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();
    }
  }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.search);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
      getWindow().setStatusBarColor(getResources().getColor(R.color.holo_blue_bright));
    }
    listmain = new ArrayList<ConRecItem>();
    tm = (EditText) findViewById(R.id.setext);
    final RecycleItemClickListener itemClickListener =
        new RecycleItemClickListener() {
          @Override
          public void onItemClick(View view, int position) {
            switch (position) {
              default:
                Intent intent = new Intent(searchActivity.this, conActivity.class);
                Data data = new Data();
                File fl = new File("/storage/sdcard0/M++/data/slist.txt");
                String spos = data.getData(fl, position + 1);
                int pos = Integer.valueOf(spos);
                intent.putExtra("pos", pos);
                startActivity(intent);
                break;
            }
          }
        };
    int displayWidth = 0;
    int displayHeight = 0;
    DisplayMetrics displayMetrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
    displayWidth = displayMetrics.widthPixels;
    displayHeight = displayMetrics.heightPixels;
    final int rpos = displayWidth / 320;
    listmain = new ArrayList<ConRecItem>();
    ConRecAdapter adapter = new ConRecAdapter(listmain, itemClickListener);
    RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler);
    recyclerView.setLayoutManager(
        new StaggeredGridLayoutManager(rpos, StaggeredGridLayoutManager.VERTICAL));
    recyclerView.setAdapter(adapter);
    tm.addTextChangedListener(
        new TextWatcher() {

          @Override
          public void beforeTextChanged(CharSequence p1, int p2, int p3, int p4) {
            // TODO: Implement this method
          }

          @Override
          public void onTextChanged(CharSequence p1, int p2, int p3, int p4) {
            // TODO: Implement this method
          }

          @Override
          public void afterTextChanged(Editable edit) {

            // TODO
            listmain = new ArrayList<ConRecItem>();
            System.out.println("okokok");
            File fs = new File("/storage/sdcard0/M++/data/fs_con.txt");
            File fl = new File("/storage/sdcard0/M++/data/slist.txt");
            String text = tm.getText().toString();
            if (fs.exists()) {
              listmain = new ArrayList<ConRecItem>();
              if (fl.exists()) {
                fl.delete();
              }

              try {
                fl.createNewFile();

                String reg = ".*" + text + ".*";

                FileReader fr = new FileReader(fs);

                BufferedReader br = new BufferedReader(fr);

                String temp = null;
                String s = "";

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

                String[] ss = s.split("\n");
                for (int i = 0; i <= ss.length; i++) {
                  try {
                    if (ss[10 * i].matches(reg)) {
                      ConRecItem p = new ConRecItem(ss[10 * i + 1], ss[10 * i]);
                      listmain.add(p);
                      String spos = String.valueOf(i);
                      Data data = new Data();
                      data.writeData(fl, spos + "\n", false);
                    }
                  } catch (ArrayIndexOutOfBoundsException e) {
                  }
                }
                ConRecAdapter adapter = new ConRecAdapter(listmain, itemClickListener);
                RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler);
                recyclerView.setLayoutManager(
                    new StaggeredGridLayoutManager(rpos, StaggeredGridLayoutManager.VERTICAL));
                recyclerView.setAdapter(adapter);

              } catch (Exception e) {
                e.printStackTrace();
              }
            }
          };
        });
  }
Exemplo n.º 8
0
 public void hideKeyboard() {
   InputMethodManager imm = (InputMethodManager) getSystemService(Activity.INPUT_METHOD_SERVICE);
   imm.hideSoftInputFromWindow(inputView.getWindowToken(), 0);
 }
Exemplo n.º 9
0
 public void clear() {
   inputView.setText("");
   listAdapter.clear();
   listAdapter.notifyDataSetChanged();
 }