Exemplo n.º 1
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // 声明二维数组
    String[][] strs = new String[5][3];
    String str = null;
    // 创建Tablelayout
    tableLayout = new TableLayout(this);
    tableLayout.setOrientation(TableLayout.VERTICAL);
    // 设定tablelayout宽高属性
    TableLayout.LayoutParams lp =
        new TableLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    // 绑定参数
    tableLayout.setLayoutParams(lp);

    for (int i = 1; i <= strs.length; i++) {
      // 创建tablerow
      TableRow tableRow = new TableRow(this);
      tableRow.setOrientation(TableRow.HORIZONTAL);
      tableRow.setBackgroundColor(Color.GREEN);
      // 设定tablerow的宽高
      TableRow.LayoutParams trLp =
          new TableRow.LayoutParams(
              TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.WRAP_CONTENT);
      tableRow.setLayoutParams(trLp);

      for (int j = 1; j <= strs[0].length; j++) {
        str = "第" + i + "行," + "第" + j + "列";

        TextView mtView = new TextView(this);

        // 添加textview文本信息
        mtView.setText(str);

        if (j == 1) {
          mtView.setBackgroundColor(Color.RED);
        } else if (j == 2) {
          mtView.setBackgroundColor(Color.GREEN);
        } else if (j == 3) {
          mtView.setBackgroundColor(Color.BLUE);
        }
        // 设定textview宽高以及权重

        TableRow.LayoutParams tvLp =
            new TableRow.LayoutParams(0, TableRow.LayoutParams.WRAP_CONTENT, 1);
        // 给textview设定参数
        mtView.setLayoutParams(tvLp);

        // 将textview添加至tablerwo中
        tableRow.addView(mtView);

        Toast.makeText(this, str, 1).show();
      }
      tableLayout.addView(tableRow);
    }
    setContentView(tableLayout);
  }
Exemplo n.º 2
0
  protected ContextDialog(
      final Context context,
      final String[] row,
      final String nickname,
      int width,
      final int defaultBgColor,
      final int defaultFoColor) {
    super(context);
    setCustomTitle(null);
    TableLayout parent = new TableLayout(context);
    parent.setStretchAllColumns(true);
    parent.setBackgroundColor(Color.WHITE);

    TableRow[] trs = new TableRow[7];
    TextView[] tvs = new TextView[7];
    String[] prefix = new String[] {"TYPE ", "ID   ", "CMD   ", "TIME ", "NG   ", "NUM  ", ""};
    for (int i = 0; i < 7; i++) {
      if (row[i] != null) {
        tvs[i] = new TextView(context);
        trs[i] = new TableRow(context);
        tvs[i].setText(prefix[i] + row[i]);
        tvs[i].setTextColor(Color.BLACK);
        trs[i].addView(tvs[i]);
        parent.addView(trs[i], new LinearLayout.LayoutParams(-1, -2));
      }
    }
    tvs[6].setWidth(width / 3 * 2);
    parent.setLayoutParams(new TableLayout.LayoutParams(-1, -1));
    parent.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            dialog.cancel();
            new HandleNamePicker(
                    (Activity) context,
                    new ColorPickerView.OnColorChangedListener() {
                      @Override
                      public void colorChanged(int color) {
                        // 色が選択されるとcolorに値が入る OKボタンで確定するので未使用
                        int R = Color.red(color);
                        int G = Color.green(color);
                        int B = Color.blue(color);
                      }
                    },
                    defaultBgColor,
                    defaultFoColor,
                    row[1],
                    nickname,
                    true)
                .show();
          }
        });
    this.setView(parent);
  }
Exemplo n.º 3
0
  // boolean selected = false;
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.create_game_menu);

    //		Canvas ca = new Canvas();
    //		Paint p = new Paint();
    //		p.setAntiAlias(true);
    //		p.setStyle(Style.STROKE);
    //		p.setStrokeWidth(5);

    TestCanvas tcanvas = new TestCanvas(this);
    Canvas canvas = new Canvas();
    tcanvas.draw(canvas);

    TableLayout layout = new TableLayout(this);
    layout.setLayoutParams(new TableLayout.LayoutParams(4, 5));

    layout.setPadding(0, 0, 50, 50);
    layout.addView((View) tcanvas);

    for (int f = 0; f < 5; f++) {
      TableRow tr = new TableRow(this);
      for (int c = 0; c < 5; c++) {
        buttons[f][c] = new Cell(this);
        buttons[f][c].setWidth(10);
        buttons[f][c].setHeight(10);
        buttons[f][c].setBackgroundColor(Color.BLACK);
        buttons[f][c].setOnClickListener(this);
        Log.i(
            "button width[" + f + "] [" + c + "] = " + "" + buttons[f][c].getWidth(),
            ("" + buttons[f][c].getWidth()));
        Log.i(
            "button height[" + f + "] [" + c + "] = " + "" + buttons[f][c].getWidth(),
            ("" + buttons[f][c].getHeight()));
        // ca.drawLine(startX, startY, stopX, stopY, p);
        tr.addView(buttons[f][c], 50, 50);
      }
      layout.addView(tr);
    }
    Button b = new Button(this);
    super.setContentView(layout);
  }
Exemplo n.º 4
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // 用代码创建TableLayout,设置宽度和高度
    TableLayout table = new TableLayout(this);
    TableLayout.LayoutParams params =
        new TableLayout.LayoutParams(
            TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.WRAP_CONTENT);

    table.setLayoutParams(params);
    for (int i = 1; i <= 10; i++) {
      // 用代码创建TableRow,设置宽度和高度
      TableRow.LayoutParams params1 =
          new TableRow.LayoutParams(
              TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT);
      TableRow row = new TableRow(this);
      row.setGravity(Gravity.CENTER);

      for (int j = 1; j <= 3; j++) {
        TableRow.LayoutParams trlp_in =
            new TableRow.LayoutParams(0, TableRow.LayoutParams.WRAP_CONTENT, 1);
        TextView view = new TextView(this);
        view.setText("行" + i + "列" + j);

        view.setLayoutParams(trlp_in);
        row.addView(view);
      }
      if (i % 2 == 0) {
        row.setBackgroundColor(Color.YELLOW);
      } else {
        row.setBackgroundColor(Color.BLUE);
      }

      table.addView(row, params1);
    }

    setContentView(table);
  }
Exemplo n.º 5
0
  private TableLayout formatTable(String text, String subreddit) {
    TableRow.LayoutParams rowParams =
        new TableRow.LayoutParams(
            TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT);

    Context context = getContext();
    TableLayout table = new TableLayout(context);
    TableLayout.LayoutParams params =
        new TableLayout.LayoutParams(
            TableLayout.LayoutParams.WRAP_CONTENT, TableLayout.LayoutParams.WRAP_CONTENT);
    table.setLayoutParams(params);

    final String tableStart = "<table>";
    final String tableEnd = "</table>";
    final String tableHeadStart = "<thead>";
    final String tableHeadEnd = "</thead>";
    final String tableRowStart = "<tr>";
    final String tableRowEnd = "</tr>";
    final String tableColumnStart = "<td>";
    final String tableColumnEnd = "</td>";
    final String tableHeaderStart = "<th>";
    final String tableHeaderEnd = "</th>";

    int i = 0;
    int columnStart = 0;
    int columnEnd;
    TableRow row = null;
    while (i < text.length()) {
      if (text.charAt(i) != '<') { // quick check otherwise it falls through to else
        i += 1;
      } else if (text.subSequence(i, i + tableStart.length()).toString().equals(tableStart)) {
        i += tableStart.length();
      } else if (text.subSequence(i, i + tableHeadStart.length())
          .toString()
          .equals(tableHeadStart)) {
        i += tableHeadStart.length();
      } else if (text.subSequence(i, i + tableRowStart.length()).toString().equals(tableRowStart)) {
        row = new TableRow(context);
        row.setLayoutParams(rowParams);
        i += tableRowStart.length();
      } else if (text.subSequence(i, i + tableRowEnd.length()).toString().equals(tableRowEnd)) {
        table.addView(row);
        i += tableRowEnd.length();
      } else if (text.subSequence(i, i + tableEnd.length()).toString().equals(tableEnd)) {
        i += tableEnd.length();
      } else if (text.subSequence(i, i + tableHeadEnd.length()).toString().equals(tableHeadEnd)) {
        i += tableHeadEnd.length();
      } else if (text.subSequence(i, i + tableColumnStart.length())
              .toString()
              .equals(tableColumnStart)
          || text.subSequence(i, i + tableHeaderStart.length())
              .toString()
              .equals(tableHeaderStart)) {
        i += tableColumnStart.length();
        columnStart = i;
      } else if (text.subSequence(i, i + tableColumnEnd.length()).toString().equals(tableColumnEnd)
          || text.subSequence(i, i + tableHeaderEnd.length()).toString().equals(tableHeaderEnd)) {
        columnEnd = i;

        SpoilerRobotoTextView textView = new SpoilerRobotoTextView(context);
        textView.setTextHtml(text.subSequence(columnStart, columnEnd), subreddit);
        setStyle(textView, subreddit);
        textView.setLayoutParams(COLUMN_PARAMS);

        row.addView(textView);

        columnStart = 0;
        i += tableColumnEnd.length();
      } else {
        i += 1;
      }
    }

    return table;
  }
  /** 初始化界面使用控件 */
  public void initInterface() {
    scrollView = new ScrollView(this);
    TableLayout table = new TableLayout(this);
    TableLayout.LayoutParams paramsTable =
        new TableLayout.LayoutParams(
            TableLayout.LayoutParams.FILL_PARENT, TableLayout.LayoutParams.FILL_PARENT);
    table.setLayoutParams(paramsTable);
    TableRow row1 = new TableRow(this);
    homeTimeLine = new Button(this);
    homeTimeLine.setText("主人页时间线");
    homeTimeLine.setId(1001);
    homeTimeLine.setOnClickListener(this);
    row1.addView(homeTimeLine);
    userTimeLine = new Button(this);
    userTimeLine.setText("客人页时间线");
    userTimeLine.setId(1002);
    userTimeLine.setOnClickListener(this);
    row1.addView(userTimeLine);
    table.addView(row1);

    TableRow row2 = new TableRow(this);
    addWeibo = new Button(this);
    addWeibo.setText("普通发表接口");
    addWeibo.setId(1003);
    addWeibo.setOnClickListener(this);
    row2.addView(addWeibo);
    addPic = new Button(this);
    addPic.setText("发表带图微博");
    addPic.setId(1004);
    addPic.setOnClickListener(this);
    row2.addView(addPic);
    table.addView(row2);

    TableRow row3 = new TableRow(this);
    addPicUrl = new Button(this);
    addPicUrl.setText("发表带网络图片微博");
    addPicUrl.setId(1005);
    addPicUrl.setOnClickListener(this);
    row3.addView(addPicUrl);
    htTimeLine = new Button(this);
    htTimeLine.setText("话题时间线");
    htTimeLine.setId(1006);
    htTimeLine.setOnClickListener(this);
    row3.addView(htTimeLine);
    table.addView(row3);

    TableRow row4 = new TableRow(this);
    userInfo = new Button(this);
    userInfo.setText("获取用户信息");
    userInfo.setId(1007);
    userInfo.setOnClickListener(this);
    row4.addView(userInfo);
    userOtherInfo = new Button(this);
    userOtherInfo.setText("获取他人信息");
    userOtherInfo.setId(1008);
    userOtherInfo.setOnClickListener(this);
    row4.addView(userOtherInfo);
    table.addView(row4);

    TableRow row5 = new TableRow(this);
    userInfos = new Button(this);
    userInfos.setText("获取一批人信息");
    userInfos.setId(1009);
    userInfos.setOnClickListener(this);
    row5.addView(userInfos);
    friendAdd = new Button(this);
    friendAdd.setText("收听某个用户");
    friendAdd.setId(1010);
    friendAdd.setOnClickListener(this);
    row5.addView(friendAdd);
    table.addView(row5);

    TableRow row6 = new TableRow(this);
    friendIdolList = new Button(this);
    friendIdolList.setText("获取偶像列表");
    friendIdolList.setId(1011);
    friendIdolList.setOnClickListener(this);
    row6.addView(friendIdolList);
    friendFunsList = new Button(this);
    friendFunsList.setText("获取粉丝列表");
    friendFunsList.setId(1012);
    friendFunsList.setOnClickListener(this);
    row6.addView(friendFunsList);
    table.addView(row6);

    TableRow row7 = new TableRow(this);
    friendMutualList = new Button(this);
    friendMutualList.setText("获取互听列表");
    friendMutualList.setId(1013);
    friendMutualList.setOnClickListener(this);
    row7.addView(friendMutualList);
    friendCheck = new Button(this);
    friendCheck.setText("验证好友关系");
    friendCheck.setId(1014);
    friendCheck.setOnClickListener(this);
    row7.addView(friendCheck);
    table.addView(row7);

    TableRow row8 = new TableRow(this);
    tReList = new Button(this);
    tReList.setText("转播获取转播列表");
    tReList.setId(1015);
    tReList.setOnClickListener(this);
    row8.addView(tReList);
    friendGetIntimateFriend = new Button(this);
    friendGetIntimateFriend.setText("获取最近联系人");
    friendGetIntimateFriend.setId(1016);
    friendGetIntimateFriend.setOnClickListener(this);
    row8.addView(friendGetIntimateFriend);
    table.addView(row8);

    TableRow row9 = new TableRow(this);
    lbsGetAroundPeople = new Button(this);
    lbsGetAroundPeople.setText("获取附近的人");
    lbsGetAroundPeople.setId(1017);
    lbsGetAroundPeople.setOnClickListener(this);
    row9.addView(lbsGetAroundPeople);
    lbsGetAroundNew = new Button(this);
    lbsGetAroundNew.setText("获取身边最新的微博");
    lbsGetAroundNew.setId(1018);
    lbsGetAroundNew.setOnClickListener(this);
    row9.addView(lbsGetAroundNew);
    table.addView(row9);

    /*TableRow row10 = new TableRow(this);
    deviceStatus = new Button(this);
    deviceStatus.setText("终端状况");
    deviceStatus.setId(1019);
    row10.addView(deviceStatus);
    errorReport = new Button(this);
    errorReport.setText("错误反馈");
    errorReport.setId(1020);
    row10.addView(errorReport);
    table.addView(row10);*/

    scrollView.addView(table);

    this.setContentView(scrollView);
  }
  @Override
  public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    if (getActivity().getIntent().getExtras() != null) {
      idSession = getActivity().getIntent().getExtras().getLong(UIUtils.MESSAGE);
      typeSession = getActivity().getIntent().getExtras().getString(UIUtils.TYPE);
    } else {
      // On gere le cas ou on tourne l'écran en restorant les états de la vue
      idSession = savedInstanceState.getLong("ID_SESSION");
      ;
      typeSession = savedInstanceState.getString("TYPE_SESSION");
    }
    Conference conference = null;
    // On recupere la session concernee
    if (TypeFile.lightningtalks.name().equals(typeSession)) {
      conference = ConferenceFacade.getInstance().getLightningtalk(getActivity(), idSession);
    } else {
      conference = ConferenceFacade.getInstance().getTalk(getActivity(), idSession);
    }

    List<Membre> speakers = new ArrayList<Membre>();
    for (Long id : conference.getSpeakers()) {
      Membre membre =
          MembreFacade.getInstance().getMembre(getActivity(), TypeFile.members.name(), id);
      if (membre != null) {
        speakers.add(membre);
      }
    }

    // On affiche les liens que si on a recuperer des choses
    if (!speakers.isEmpty()) {
      // On utilisait auparavant une liste pour afficher ces éléments dans la page mais cette liste
      // empêche d'avoir un ScrollView englobant pour toute la page. Nous utilisons donc un tableau
      linearLayoutRoot =
          (LinearLayout) mInflater.inflate(R.layout.fragment_linear, mRootView, false);

      // On vide les éléments
      linearLayoutRoot.removeAllViews();

      // On ajoute un table layout
      TableLayout.LayoutParams tableParams =
          new TableLayout.LayoutParams(
              TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.WRAP_CONTENT);
      TableLayout tableLayout = new TableLayout(getActivity().getBaseContext());
      tableLayout.setLayoutParams(tableParams);

      for (final Membre membre : speakers) {
        RelativeLayout row = (RelativeLayout) mInflater.inflate(R.layout.person_item, null);
        row.setBackgroundResource(R.drawable.row_transparent_background);

        // Dans lequel nous allons ajouter le contenu que nous faisons mappé dans
        userName = (TextView) row.findViewById(R.id.person_user_name);
        descriptif = (TextView) row.findViewById(R.id.person_shortdesciptif);
        level = (TextView) row.findViewById(R.id.person_level);
        profileImage = (ImageView) row.findViewById(R.id.person_user_image);

        userName.setText(membre.getCompleteName());

        if (membre.getShortdesc() != null) {
          descriptif.setText(membre.getShortdesc().trim());
        }

        if (membre.getLevel() != null && !membre.getLevel().isEmpty()) {
          level.setText("[" + membre.getLevel().trim() + "]");
        }

        // Recuperation de l'mage liee au profil
        Bitmap image = FileUtils.getImageProfile(getActivity(), membre);
        if (image == null) {
          profileImage.setImageDrawable(getResources().getDrawable(R.drawable.person_image_empty));
        } else {
          // On regarde dans les images embarquees
          profileImage.setImageBitmap(image);
        }

        row.setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                Map<String, Object> parameters = new HashMap<String, Object>(2);
                parameters.put(UIUtils.MESSAGE, membre.getId());
                parameters.put(UIUtils.TYPE, TypeFile.speaker);
                UIUtils.startActivity(MembreActivity.class, getActivity(), parameters);
              }
            });

        tableLayout.addView(row);
      }

      linearLayoutRoot.addView(tableLayout);
      mRootView.addView(linearLayoutRoot);
    }
  }
  public AddPlayersToGameView(Context context) {
    this.context = context;

    mainScrollView = new ScrollView(context);
    mainScrollView.setFillViewport(true);
    mainScrollView.setLayoutParams(
        new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));

    LinearLayout mainView = new LinearLayout(context);
    mainView.setGravity(Gravity.CENTER_HORIZONTAL);
    LinearLayout.LayoutParams mainLayoutParams =
        new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT);
    mainLayoutParams.leftMargin = UIConstants.MARGIN_SIZE;
    mainLayoutParams.rightMargin = UIConstants.MARGIN_SIZE;
    mainView.setLayoutParams(mainLayoutParams);
    BackgroundUtil.setBackground(mainView);
    mainView.setOrientation(LinearLayout.VERTICAL);
    mainScrollView.addView(mainView);

    TextView title = new TextView(context);
    title.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
    title.setText("Add Players");
    title.setTextSize(UIConstants.TEXT_TITLE_SIZE);
    title.setTextColor(UIConstants.TEXT_COLOR);
    title.setGravity(Gravity.CENTER_HORIZONTAL);
    mainView.addView(title);

    LinearLayout controlView = new LinearLayout(context);
    controlView.setGravity(Gravity.CENTER_HORIZONTAL);
    LinearLayout.LayoutParams controlViewLayouParams =
        new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
    controlViewLayouParams.leftMargin = UIConstants.MARGIN_SIZE;
    controlViewLayouParams.rightMargin = UIConstants.MARGIN_SIZE;
    controlView.setLayoutParams(controlViewLayouParams);
    controlView.setOrientation(LinearLayout.HORIZONTAL);
    mainView.addView(controlView);

    Button firstDoneButton = new Button(context);
    firstDoneButton.setLayoutParams(
        new LayoutParams(LayoutParams.FILL_PARENT, UIConstants.BUTTON_HEIGHT));
    firstDoneButton.setText("Done");
    firstDoneButton.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            doneButtonListenerManager.notifyListeners();
          }
        });
    controlView.addView(firstDoneButton);

    allPlayersTable = new TableLayout(context);
    allPlayersTable.setLayoutParams(
        new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));

    allPlayersTable.setGravity(Gravity.CENTER_HORIZONTAL);
    TableLayout.LayoutParams allPlayersTableLayoutParams =
        new TableLayout.LayoutParams(
            TableLayout.LayoutParams.FILL_PARENT, TableLayout.LayoutParams.WRAP_CONTENT);
    allPlayersTableLayoutParams.leftMargin = UIConstants.MARGIN_SIZE;
    allPlayersTableLayoutParams.rightMargin = UIConstants.MARGIN_SIZE;
    allPlayersTable.setLayoutParams(allPlayersTableLayoutParams);

    allPlayersTable.setColumnStretchable(1, true);
    mainView.addView(allPlayersTable);

    Button secondDoneButton = new Button(context);
    secondDoneButton.setLayoutParams(
        new LayoutParams(LayoutParams.FILL_PARENT, UIConstants.BUTTON_HEIGHT));
    secondDoneButton.setText("Done");
    secondDoneButton.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            doneButtonListenerManager.notifyListeners();
          }
        });
    controlView.addView(secondDoneButton);
  }
  public void plotData() {
    LinearLayout linearLayout = (LinearLayout) findViewById(R.id.scanningResultBlock);
    linearLayout.removeAllViews();

    if (mWifiData == null) {
      Log.d(TAG, "Plotting data: no networks");
      TextView noDataView = new TextView(this);
      noDataView.setText(getResources().getString(R.string.wifi_no_data));
      noDataView.setGravity(Gravity.CENTER_HORIZONTAL);
      noDataView.setPadding(0, 50, 0, 0);
      noDataView.setTextSize(18);
      linearLayout.addView(noDataView);
    } else {
      Log.d(TAG, "Plotting data");

      TableLayout.LayoutParams tableParams =
          new TableLayout.LayoutParams(
              TableLayout.LayoutParams.WRAP_CONTENT, TableLayout.LayoutParams.WRAP_CONTENT);
      TableRow.LayoutParams rowParams =
          new TableRow.LayoutParams(
              TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT);

      TableLayout tableLayout = new TableLayout(this);
      tableLayout.setLayoutParams(tableParams);
      tableLayout.setStretchAllColumns(true);

      // row header
      TableRow tableRowHeader = new TableRow(this);
      tableRowHeader.setLayoutParams(rowParams);

      TextView ssidText = new TextView(this);
      ssidText.setText(getResources().getString(R.string.ssid_text));
      ssidText.setTypeface(null, Typeface.BOLD);

      TextView chText = new TextView(this);
      chText.setText(getResources().getString(R.string.ch_text));
      chText.setTypeface(null, Typeface.BOLD);

      TextView rxText = new TextView(this);
      rxText.setText(getResources().getString(R.string.rx_text));
      rxText.setTypeface(null, Typeface.BOLD);

      int orientation = getResources().getConfiguration().orientation;
      if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
        TextView bssidText = new TextView(this);
        bssidText.setText(getResources().getString(R.string.bssid_text));
        bssidText.setTypeface(null, Typeface.BOLD);

        tableRowHeader.addView(ssidText);
        tableRowHeader.addView(bssidText);
        tableRowHeader.addView(chText);
        tableRowHeader.addView(rxText);
      } else {
        tableRowHeader.addView(ssidText);
        tableRowHeader.addView(chText);
        tableRowHeader.addView(rxText);
      }

      tableLayout.addView(tableRowHeader);

      // rows data
      for (WifiDataNetwork net : mWifiData.getNetworks()) {
        TextView ssidVal = new TextView(this);
        ssidVal.setText(net.getSsid());

        TextView chVal = new TextView(this);
        chVal.setText(
            String.valueOf(WifiDataNetwork.convertFrequencyToChannel(net.getFrequency())));

        TextView rxVal = new TextView(this);
        rxVal.setText(String.valueOf(net.getLevel()));

        TableRow tableRow = new TableRow(this);
        tableRow.setLayoutParams(rowParams);

        if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
          TextView bssidVal = new TextView(this);
          bssidVal.setText(net.getBssid());

          rxVal.setText(String.valueOf(net.getLevel()) + " dBm");

          tableRow.addView(ssidVal);
          tableRow.addView(bssidVal);
          tableRow.addView(chVal);
          tableRow.addView(rxVal);
        } else {
          tableRow.addView(ssidVal);
          tableRow.addView(chVal);
          tableRow.addView(rxVal);
        }

        tableLayout.addView(tableRow);
      }

      linearLayout.addView(tableLayout);
    }
  }
Exemplo n.º 10
0
 @Override
 public void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   requestWindowFeature(Window.FEATURE_NO_TITLE);
   try { // try to get matrix config
     String fname = "battleship";
     File file = getBaseContext().getFileStreamPath(fname);
     if (file.exists()) { // read from file
       DataInputStream in = new DataInputStream(openFileInput(fname));
       for (int i = 0; i < 10; i++) {
         for (int j = 0; j < 10; j++) {
           P1[i][j] = Integer.parseInt(in.readUTF());
         }
       }
       for (int i = 0; i < 10; i++) {
         for (int j = 0; j < 10; j++) {
           P2[i][j] = Integer.parseInt(in.readUTF());
         }
       }
       in.close();
     }
   } catch (IOException e) {
     Log.i("Data Input Sample", "I/O Error");
   }
   RelativeLayout hugelay = new RelativeLayout(this);
   ScrollView largelay = new ScrollView(this);
   largelay.setId(10000);
   TableLayout layout = new TableLayout(this);
   layout.setLayoutParams(new TableLayout.LayoutParams(300, 300));
   layout.setPadding(1, 1, 1, 1);
   int i, j;
   for (i = 0; i <= 9; i++) {
     TableRow tr = new TableRow(this);
     for (j = 0; j <= 9; j++) {
       ImageButton b = new ImageButton(this);
       if (P2[i][j] == 0) {
         b.setImageResource(R.drawable.water);
       } else if (P2[i][j] == 99) {
         b.setImageResource(R.drawable.explosion);
       } else if (P2[i][j] == 88) {
         b.setImageResource(R.drawable.x);
       } else {
         b.setImageResource(R.drawable.water2);
       }
       b.setId(i * 10 + j);
       b.setOnClickListener(this);
       tr.addView(b, 72, 72);
     } // for
     layout.addView(tr);
   } // for
   largelay.addView(layout);
   hugelay.setBackgroundResource(R.drawable.battleshipbg);
   Button btn = new Button(this);
   btn.setText("MY MAP");
   btn.setBackgroundResource(R.color.transparent);
   btn.setHeight(134);
   btn.setWidth(134);
   btn.setId(1000);
   btn.setOnClickListener(this);
   RelativeLayout.LayoutParams lp =
       new RelativeLayout.LayoutParams(
           RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
   lp.addRule(RelativeLayout.RIGHT_OF, largelay.getId());
   lp.addRule(RelativeLayout.CENTER_VERTICAL);
   hugelay.addView(largelay);
   hugelay.addView(btn, lp);
   super.setContentView(hugelay);
 } // ()