@Override public void onTextSizeChanged(final TextView textView, float oldSize) { if (mCurrentState != CalculatorState.INPUT) { // TODO dont animate when showing graph // Only animate text changes that occur from user input. return; } // Calculate the values needed to perform the scale and translation animations, // maintaining the same apparent baseline for the displayed text. final float textScale = oldSize / textView.getTextSize(); final float translationX; if (android.os.Build.VERSION.SDK_INT >= 17) { translationX = (1.0f - textScale) * (textView.getWidth() / 2.0f - textView.getPaddingEnd()); } else { translationX = (1.0f - textScale) * (textView.getWidth() / 2.0f - textView.getPaddingRight()); } final float translationY = (1.0f - textScale) * (textView.getHeight() / 2.0f - textView.getPaddingBottom()); final AnimatorSet animatorSet = new AnimatorSet(); animatorSet.playTogether( ObjectAnimator.ofFloat(textView, View.SCALE_X, textScale, 1.0f), ObjectAnimator.ofFloat(textView, View.SCALE_Y, textScale, 1.0f), ObjectAnimator.ofFloat(textView, View.TRANSLATION_X, translationX, 0.0f), ObjectAnimator.ofFloat(textView, View.TRANSLATION_Y, translationY, 0.0f)); animatorSet.setDuration(getResources().getInteger(android.R.integer.config_mediumAnimTime)); animatorSet.setInterpolator(new AccelerateDecelerateInterpolator()); animatorSet.start(); }
/** * @param textview * @return */ private String adjustTextLength(TextView tv) { if (tv == null) { return ""; } String input = tv.getText().toString(); String result = input; String newtext = input; int lastSpaceIndex = 0; ViewGroup.LayoutParams lp = (ViewGroup.LayoutParams) tv.getLayoutParams(); Paint p = tv.getPaint(); Rect bound = new Rect(); p.getTextBounds(input, 0, input.length() - 1, bound); float textHeight = p.getTextSize(); float multiLine = (((lp.height - tv.getPaddingTop() - tv.getPaddingBottom()) / textHeight)); float availableW = (lp.width - tv.getPaddingLeft() - tv.getPaddingRight()) * (multiLine + 0.2f); do { newtext = (String) TextUtils.ellipsize(result, tv.getPaint(), availableW, TruncateAt.END); if (!newtext.equals(result)) { lastSpaceIndex = newtext.lastIndexOf(" "); if (lastSpaceIndex > 0) { result = newtext.substring(0, lastSpaceIndex) + "..."; } else { break; } } else { break; } } while (false); GKIMLog.lf(null, 0, TAG + "=>adjust title from: " + input + " to: " + result); tv.setText(result); return result; }
@Override public View getView(int position, View convertView, ViewGroup parent) { PromptListItem item = getItem(position); ViewHolder viewHolder = null; if (convertView == null) { int resourceId = mResourceId; if (item.isGroup) { resourceId = R.layout.list_item_header; } convertView = mInflater.inflate(resourceId, null); convertView.setMinimumHeight(mMinRowSize); TextView tv = (TextView) convertView.findViewById(android.R.id.text1); viewHolder = new ViewHolder( tv, tv.getPaddingLeft(), tv.getPaddingRight(), tv.getPaddingTop(), tv.getPaddingBottom()); convertView.setTag(viewHolder); } else { viewHolder = (ViewHolder) convertView.getTag(); } viewHolder.textView.setText(item.label); maybeUpdateCheckedState(position, item, viewHolder); maybeUpdateIcon(item, viewHolder.textView); return convertView; }
public android.view.View getDropDownView(int i, android.view.View v, android.view.ViewGroup p) { android.widget.TextView res = null; res = rs.android.ui.Util.New_Label(p.getContext(), this.items[i], null); res.setPadding( res.getPaddingLeft() + 20, res.getPaddingTop() + 10, res.getPaddingRight() + 10, res.getPaddingBottom() + 15); return res; }
private int chooseSize(PopupWindow pop, View parentView, CharSequence text, TextView tv) { int wid = tv.getPaddingLeft() + tv.getPaddingRight(); int ht = tv.getPaddingTop() + tv.getPaddingBottom(); /* * Figure out how big the text would be if we laid it out to the * full width of this view minus the border. */ int cap = width - wid; Layout l = new StaticLayout(text, tv.getPaint(), cap, Layout.Alignment.ALIGN_NORMAL, 1, 0, true); float max = 0; for (int i = 0; i < l.getLineCount(); i++) { max = Math.max(max, l.getLineWidth(i)); } /* * Now set the popup size to be big enough for the text plus the border. */ pop.setWidth(width); pop.setHeight(ht + l.getHeight()); return l.getHeight(); }
public static ScrollView generateTeamLayout(Context context, boolean pit) { RelativeLayout layout = new RelativeLayout(context); ScrollView scrollView = new ScrollView(context); BufferedReader reader = new BufferedReader( new InputStreamReader( context .getResources() .openRawResource(pit ? R.raw.team_config_pit : R.raw.team_config_match))); try { String line = reader.readLine(); // The version Log.d( MainActivity.APP_TAG, "Loaded " + (pit ? "pit" : "match") + " config file version " + line); if (pit) configVersionPit = line; else configVersionMatch = line; int last = -1; while ((line = reader.readLine()) != null) { TextView header = null; View[] view; int idOffset = Integer.MAX_VALUE; String[] l; if (line.contains(":")) { l = line.split(":"); RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); header = new TextView(context); header.setText(l[1].substring(2)); header.setTextSize(20f); header.setId(idOffset - View.generateViewId()); if (last != -1) { if (l[1].charAt(1) == '0') params.addRule(RelativeLayout.BELOW, last); else { params.addRule(RelativeLayout.RIGHT_OF, last); params.addRule(RelativeLayout.ALIGN_TOP, last); } } header.setPadding( header.getPaddingLeft(), header.getPaddingTop(), header.getPaddingRight() + 20, header.getPaddingBottom()); header.setLayoutParams(params); boolean below = false; switch (Integer.parseInt(l[1].charAt(0) + "")) { case 0: // Checkbox view = new View[] {new CheckBox(context)}; break; case 1: // Spinner Spinner spinner = new Spinner(context); ArrayList<String> l1 = new ArrayList<>(); l1.add("None"); l1.addAll(Arrays.asList(l[2].split(","))); spinner.setAdapter( new ArrayAdapter<>(context, android.R.layout.simple_spinner_dropdown_item, l1)); view = new View[] {spinner}; break; case 2: { // Number EditText editText = new EditText(context); editText.setInputType(InputType.TYPE_CLASS_NUMBER); editText.setSingleLine(); editText.setImeOptions(0x00000005); // Next view = new View[] {editText}; break; } case 3: { // Text EditText editText = new EditText(context); editText.setSingleLine(); editText.setImeOptions(0x00000005); // Next view = new View[] {editText}; break; } case 4: // Text for Teams AutoCompleteTextView autoCompleteTextView = new AutoCompleteTextView(context); autoCompleteTextView.setAdapter( new ArrayAdapter<>( context, android.R.layout.simple_dropdown_item_1line, MainActivity.teamList)); autoCompleteTextView.setSingleLine(); autoCompleteTextView.setImeOptions(0x00000005); // Next view = new View[] {autoCompleteTextView}; break; case 5: { // Multiline field EditText editText = new EditText(context); editText.setSingleLine(false); view = new View[] {editText}; below = true; break; } case 6: { // Number Entry with Plus final EditText editText = new EditText(context); ImageButton button = new ImageButton(context); button.setImageResource(R.drawable.ic_action_new); button.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { if (editText.getText().toString().equals("")) editText.setText("1"); else editText.setText( "" + (Integer.parseInt(editText.getText().toString()) + 1)); } }); editText.setInputType(InputType.TYPE_CLASS_NUMBER); editText.setSingleLine(); editText.setImeOptions(0x00000005); // Next view = new View[] {editText, button}; break; } default: Log.e( MainActivity.APP_TAG, "Invalid file format for team config, error at line: " + line); return null; } if (view.length == 1) { RelativeLayout.LayoutParams params1 = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); if (below) params1.addRule(RelativeLayout.BELOW, header.getId()); else { params1.addRule(RelativeLayout.ALIGN_TOP, header.getId()); params1.addRule(RelativeLayout.RIGHT_OF, header.getId()); } view[0].setId(Integer.parseInt(l[0])); view[0].setLayoutParams(params1); } else { for (int i = 0; i < view.length; i++) { RelativeLayout.LayoutParams params1 = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); if (i == 0) { if (below) params1.addRule(RelativeLayout.BELOW, header.getId()); else { params1.addRule(RelativeLayout.ALIGN_TOP, header.getId()); params1.addRule(RelativeLayout.RIGHT_OF, header.getId()); } view[0].setId(Integer.parseInt(l[0])); view[0].setLayoutParams(params1); continue; } params1.addRule(RelativeLayout.ALIGN_TOP, view[i - 1].getId()); params1.addRule(RelativeLayout.RIGHT_OF, view[i - 1].getId()); view[i].setId(Integer.parseInt(l[0]) + i); view[i].setLayoutParams(params1); } } } else { RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); TextView v = new TextView(context); v.setText(line); v.setTextSize(30f); v.setId(idOffset - View.generateViewId()); if (last != -1) params.addRule(RelativeLayout.BELOW, last); v.setLayoutParams(params); view = new View[] {v}; } if (header != null) layout.addView(header); for (View v : view) layout.addView(v); last = view[view.length - 1].getId(); } } catch (IOException e) { e.printStackTrace(); } scrollView.addView(layout); return scrollView; }
private void setMarginParams(int margin, TextView textView) { textView.setPadding( textView.getPaddingLeft(), textView.getPaddingTop(), margin, textView.getPaddingBottom()); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Remove title bar this.requestWindowFeature(Window.FEATURE_NO_TITLE); // Remove notification bar this.getWindow() .setFlags( WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); // set content view AFTER ABOVE sequence (to avoid crash) setContentView(R.layout.player); decorView = getWindow().getDecorView(); uiOption = getWindow().getDecorView().getSystemUiVisibility(); surfaceView = (SurfaceView) this.findViewById(R.id.SurfaceView); surfaceHolder = surfaceView.getHolder(); surfaceHolder.addCallback(this); mediaPlayer = new MediaPlayer(); mediaPlayer.setOnCompletionListener(this); mediaPlayer.setOnErrorListener(this); mediaPlayer.setOnInfoListener(this); mediaPlayer.setOnPreparedListener(this); mediaPlayer.setOnSeekCompleteListener(this); mediaPlayer.setOnVideoSizeChangedListener(this); mMenuBar = (RelativeLayout) findViewById(R.id.menuBar); mMenuButton = (ImageView) findViewById(R.id.menuButton); mVideoList = (LinearLayout) findViewById(R.id.videoList); mTitle = (TextView) findViewById(R.id.MovieTitle); mMenuButton.setOnClickListener(this); mVideoList.setOnClickListener(this); /* * String filePath = Environment.getExternalStorageDirectory().getPath() * + "/Movies/Spanglish_H264_AAC_800x432.mp4"; */ // POINT: sdcard 의 동영상 파일 목록을 구하기 String sdPath = Environment.getExternalStorageDirectory().getAbsolutePath(); File sdRoot = new File(sdPath); FileList(sdRoot); for (int i = 0; i < mFileList.size(); i++) { if ((mFileList.get(i).endsWith(".mp4")) || (mFileList.get(i).endsWith(".mkv"))) { Log.e("TAT", mFileList.get(i)); mVideoFileList.add(mFileList.get(i)); } } if (mVideoFileList.isEmpty()) { Toast.makeText(this, "재생할 파일이 없습니다.", 1).show(); } for (int i = 0; i < mVideoFileList.size(); i++) { final String path = mVideoFileList.get(i); final String filename = path.substring(path.lastIndexOf("/") + 1); final TextView text = new TextView(this); text.setContentDescription(i + ""); text.setSingleLine(); text.setPadding( text.getPaddingLeft() + 10, text.getPaddingTop() + 10, text.getPaddingRight(), text.getPaddingBottom()); text.setHeight(80); text.setText(filename); text.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { try { if (mediaPlayer.isPlaying()) mediaPlayer.stop(); mediaPlayer.reset(); mediaPlayer.setDataSource(path); mediaPlayer.prepare(); idx = Integer.parseInt(text.getContentDescription().toString()); mTitle.setText("[ " + filename + " ]"); } catch (IllegalArgumentException e) { Log.v(LOGTAG, e.getMessage()); finish(); } catch (IllegalStateException e) { Log.v(LOGTAG, e.getMessage()); finish(); } catch (SecurityException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }); mVideoList.addView(text); } /* TODO : intend를 통해 클릭한 동영상 path 넘겨주기 */ // Intent intent = getIntent(); // mmList = intent.getStringArrayListExtra("vList"); String filePath = mVideoFileList.get(0); try { mediaPlayer.setDataSource(filePath); String filename = filePath.substring(filePath.lastIndexOf("/") + 1); mTitle.setText("[ " + filename + " ]"); } catch (IllegalArgumentException e) { Log.v(LOGTAG, e.getMessage()); finish(); } catch (IllegalStateException e) { Log.v(LOGTAG, e.getMessage()); finish(); } catch (IOException e) { Log.v(LOGTAG, e.getMessage()); finish(); } controller = new MediaController(this) { @Override public void show() { super.show(0); mMenuBar.setVisibility(View.VISIBLE); } @Override public void hide() { super.hide(); mMenuBar.setVisibility(View.INVISIBLE); ((ScrollView) mVideoList.getParent()).setVisibility(View.INVISIBLE); } }; currentDisplay = getWindowManager().getDefaultDisplay(); // // if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) // uiOption |= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; }