Okhelp.cz

Recepty, články, nápady, programování. Dříve dum-zahrada, finance, internet a know-how.okhelp.cz Pro lepší výsledky hledání používejte i diakritiku.

Pixel to density independent pixel to pixel conversion


AD MOB

Physical pixel (px)
Density independent pixel (dp)
Dots per inch (dpi) .. physical pixels per inch
px = dp * (dpi / 160)

public static int dpToPx(int dp)
{
    return (int) (dp * Resources.getSystem().getDisplayMetrics().density);
}

public static int pxToDp(int px)
{
    return (int) (px / Resources.getSystem().getDisplayMetrics().density);
}

397LW NO topic_id




AD

Další témata ....(Topics)


126

onSensorChanged Android example | onsensorchanged-android-example


Sensor, getSystemService(), getSensorList(), getDefaultDisplay(), WindowManager,
Surface.ROTATION_0, onAccuracyChanged() Android sample.

public class _MotionActivity extends Activity implements SensorEventListener {
    private float mSensorX;
    private float mSensorY;
    private Display mDisplay;
    private SensorManager sm;
    private PowerManager mPowerManager;
    private WindowManager mWindowManager;
   
    TextView textview;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // Get an instance of the SensorManager
        sm = (SensorManager) getSystemService(SENSOR_SERVICE);
        if(sm.getSensorList(Sensor.TYPE_ACCELEROMETER).size()!=0){
        	Sensor s = sm.getSensorList(Sensor.TYPE_ACCELEROMETER).get(0);
        	sm.registerListener(this,s, SensorManager.SENSOR_DELAY_NORMAL);
        }

        // Get an instance of the PowerManager
        mPowerManager = (PowerManager) getSystemService(POWER_SERVICE);

        // Get an instance of the WindowManager
        mWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
        mDisplay = mWindowManager.getDefaultDisplay();

 
        
        setContentView(R.layout.main);
        textview = (TextView)findViewById(R.id.textView1);
    }
    
    @Override
    public void onSensorChanged(SensorEvent event) {

    	
        if (event.sensor.getType() != Sensor.TYPE_ACCELEROMETER)
            return;

        switch (mDisplay.getRotation()) {
            case Surface.ROTATION_0:
                mSensorX = event.values[0];
                mSensorY = event.values[1];
                textview.setText(String.valueOf( mSensorX));
                break;
            case Surface.ROTATION_90:
                mSensorX = -event.values[1];
                mSensorY = event.values[0];
                textview.setText(String.valueOf( mSensorX));
                break;
            case Surface.ROTATION_180:
                mSensorX = -event.values[0];
                mSensorY = -event.values[1];
                textview.setText(String.valueOf( mSensorX));
                break;
            case Surface.ROTATION_270:
                mSensorX = event.values[1];
                mSensorY = -event.values[0];
                textview.setText(String.valueOf( mSensorX));
                break;
        }

    }

	@Override
	public void onAccuracyChanged(Sensor sensor, int accuracy) {
		// TODO Auto-generated method stub
		
	}
	@Override
	protected void onResume() {
		super.onResume();

             if(sm.getSensorList(Sensor.TYPE_ACCELEROMETER).size()!=0){
        	Sensor s = sm.getSensorList(Sensor.TYPE_ACCELEROMETER).get(0);
        	sm.registerListener(this,s, SensorManager.SENSOR_DELAY_NORMAL);
             }
	}

	@Override
	protected void onPause() {
		
		sm.unregisterListener(this);
		super.onStop();
	}       
    
}

208

Zipalign ADT Eclipse | zipalign-adt-eclipse


Zipalign.exe path on Windows:
c:\Program Files\Android\android-sdk-windows\tools\zipalign.exe

zipalign [-f] [-v] <alignment> infile.apk outfile.apk

// command line in Total Commander
zipalign.exe -f -v 4 infile.apk outfile.apk

When using Eclipse with the ADT plugin, the Export Wizard will automatically zipalign your .apk after it signs it with your private key.


How do signs .apk with your private key - image:


signs-apk-with-eclipse-android-1

signs-apk-with-eclipse-android-1

signs-apk-with-eclipse-android-1

signs-apk-with-eclipse-android-1

signs-apk-with-eclipse-android-1

More about Zipalign android.com
326

phpbb forum mobile friendly theme style | phpbb-forum-mobile-friendly-theme-style


- download any mobile styles for example //www.artodia.com/phpbb-styles/mobile/
- unzip style into your forum style folder for example all art_mobile folder copy into 0:/myweb/forum/styles/
- folow instalation istructions //www.artodia.com/phpbb-styles/mobile/tutorials/mobile-detection/
- check url result on https://www.google.com/webmasters/tools/mobile-friendly
386

Android Studio Gradle Download Link | android-studio-gradle-download-link


I You use offline work for better building speed of project or for other purpose
https://gradle.org/releases

Offline work:
File - Settings - Gradle
- select Use local gradle distribution
- select path Gradle home:
- check Offline work
89

Map TreeMap get key by value Java Android example | map-treemap-get-key-by-value-java-android-example


Get key by value from Map Java Android example


MainClass.java

import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.TreeMap;

public class MainClass {
	public static void main(String[] arg) {

		// english;germany dictionary
		String[] arrayOfString = { "one;eine", "two;zwei", "two sets of;zwei"
				, "three;drei", "four;vier" };

		Map<String, String> map = new TreeMap<String, String>();

		for (String s : arrayOfString) {
			String[] array = s.split(";");
			String sKey = "", sValue = "";
			if (array.length > 1) {
				sKey = array[0];
				sValue = array[1];
				map.put(sKey, sValue);
			}
		}

		if (map.containsValue("zwei")) {
			Set<String> references = getKeysByValue(map, "zwei");
			 Iterator<String> it = references.iterator();
			    while (it.hasNext()) {
			      String key = (String) it.next();
			      String value = map.get(key);
			      System.out.println(key + " = " + value);
			    }
		}

	}

	public static <T, E> Set<T> getKeysByValue(Map<T, E> map, E value) {
		Set<T> keys = new HashSet<T>();
		for (Entry<T, E> entry : map.entrySet()) {
			if (entry.getValue().equals(value)) {
				keys.add(entry.getKey());
			}
		}
		return keys;
	}
}
/*
two = zwei
two sets of = zwei
 */



Editace: 2015-12-02 19:01:06
Počet článků v kategorii: 397
Url:pixel-to-density-independent-pixel-to-pixel-conversion

AD
11 Share
Share
Tweet