on Monday, August 24, 2015
I have 2 layouts for the primary screen of a small app I built. One layout is for portrait and one layout is for landscape.

The landscape version looks just how I want it.

landscape

Here is the XML code for this layout:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/gradient"
    android:gravity="center_horizontal|top"
    tools:context=".Main">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:gravity="center">

        <ProgressBar
            android:id="@+id/consumption_progress_bar"
            style="?android:attr/progressBarStyleHorizontal"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:indeterminate="false"
            android:max="100"
            android:progress="0"
            android:progressDrawable="@drawable/progressbar"
            android:secondaryProgress="100" />

        <ProgressBar
            android:id="@+id/time_progress_bar"
            style="?android:attr/progressBarStyleHorizontal"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:indeterminate="false"
            android:max="100"
            android:progress="0"
            android:progressDrawable="@drawable/progressbar2"
            android:secondaryProgress="100" />

        <TextView
            android:id="@+id/water_consumed"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:maxLines="1"
            android:layout_centerInParent="true"
            android:textColor="@color/white"
            android:fontFamily="sans-serif-light"
            android:textSize="40sp" />

        <TextView
            android:id="@+id/unit"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:maxLines="1"
            android:textColor="@color/white"
            android:layout_centerInParent="true"
            android:layout_below="@id/water_consumed"
            android:fontFamily="sans-serif-light"
            android:text="@string/milliliters_abbrev"
            android:textSize="16sp" />

    </RelativeLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:gravity="center"
        android:orientation="vertical">

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <TextView
                android:id="@+id/glass"
                style="@style/ButtonSmall"
                android:layout_width="80dip"
                android:layout_height="80dip"
                android:gravity="center"
                android:background="@drawable/whitebutton_small"
                android:text="@string/glass"
                android:fontFamily="sans-serif-light" />

            <View
                android:layout_width="@dimen/spacer"
                android:layout_height="@dimen/spacer" />

            <TextView
                android:id="@+id/custom"
                style="@style/ButtonSmall"
                android:layout_width="80dip"
                android:layout_height="80dip"
                android:gravity="center"
                android:background="@drawable/whitebutton_small"
                android:text="@string/custom"
                android:fontFamily="sans-serif-light" />
        </LinearLayout>

        <View
            android:layout_width="@dimen/spacer"
            android:layout_height="@dimen/spacer" />

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <TextView
                android:id="@+id/small_bottle"
                style="@style/ButtonSmall"
                android:layout_width="80dip"
                android:layout_height="80dip"
                android:gravity="center"
                android:background="@drawable/whitebutton_small"
                android:text="@string/small_bottle"
                android:fontFamily="sans-serif-light" />

            <View
                android:layout_width="@dimen/spacer"
                android:layout_height="@dimen/spacer" />

            <TextView
                android:id="@+id/large_bottle"
                style="@style/ButtonSmall"
                android:layout_width="80dip"
                android:layout_height="80dip"
                android:gravity="center"
                android:background="@drawable/whitebutton_small"
                android:text="@string/large_bottle"
                android:fontFamily="sans-serif-light" />
        </LinearLayout>

    </LinearLayout>
</LinearLayout>

The portrait XML is the exact same XML except the top-most LinearLayout has android:orientation="vertical" added to it.

However, when in portrait mode, the progress bars size themselves bigger than the view that contains them.

enter image description here

I suspect this is because half of the screen is not a perfect square, and the View containing the ProgressBar should be a square. Does anyone know how to accomplish my goal here?

on Sunday, April 19, 2015


I follow the tutorial of Google about blobstore


https://cloud.google.com/appengine/docs/java/blobstore/#Java_Complete_sample_application


However when i deploy the project to app engine i get the 500 Server Error


these are my classes:


serve class:



import java.io.IOException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.appengine.api.blobstore.BlobKey;
import com.google.appengine.api.blobstore.BlobstoreService;
import com.google.appengine.api.blobstore.BlobstoreServiceFactory;

public class Serve extends HttpServlet {
private BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();

@Override
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws IOException {
BlobKey blobKey = new BlobKey(req.getParameter("blob-key"));
blobstoreService.serve(blobKey, res);
}
}


upload class:



package com.example.photo;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.appengine.api.blobstore.BlobKey;
import com.google.appengine.api.blobstore.BlobstoreService;
import com.google.appengine.api.blobstore.BlobstoreServiceFactory;

public class Upload extends HttpServlet {
private BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();

@Override
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {

Map<String, List<BlobKey>> blobs = blobstoreService.getUploads(req);
List<BlobKey> blobKeys = blobs.get("myFile");

if (blobKeys == null || blobKeys.isEmpty()) {
res.sendRedirect("/");
} else {
res.sendRedirect("/serve?blob-key=" + blobKeys.get(0).getKeyString());
}
}
}


index.jsp



<%@ page import="com.google.appengine.api.blobstore.BlobstoreServiceFactory" %>
<%@ page import="com.google.appengine.api.blobstore.BlobstoreService" %>



<html>
<head>
<title>Upload Test</title>
</head>
<body>
<form action="<%= blobstoreService.createUploadUrl("/upload") %>" method="post" enctype="multipart/form-data">
<input type="text" name="foo">
<input type="file" name="myFile">
<input type="submit" value="Submit">
</form>
</body>
</html>


web.xml



<?xml version="1.0" encoding="utf-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">

<servlet>
<servlet-name>Upload</servlet-name>
<servlet-class>com.direction.investor.fileuploader.Upload</servlet-class>
</servlet>

<servlet>
<servlet-name>Serve</servlet-name>
<servlet-class>com.direction.investor.fileuploader.Serve</servlet-class>



<servlet-mapping>
<servlet-name>Upload</servlet-name>
<url-pattern>/upload</url-pattern>
</servlet-mapping>

<servlet-mapping>
<servlet-name>Serve</servlet-name>
<url-pattern>/serve</url-pattern>
</servlet-mapping>


appengine-web.xml



<?xml version="1.0" encoding="utf-8"?>
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
<application>optical-wall-92019</application>
<version>1</version>

<!--
Allows App Engine to send multiple requests to one instance in parallel:
-->
<threadsafe>true</threadsafe>

<!-- Configure serving/caching of GWT files -->
<static-files>
<include path="**" />

<!-- The following line requires App Engine 1.3.2 SDK -->
<include path="**.nocache.*" expiration="0s" />

<include path="**.cache.*" expiration="365d" />
<exclude path="**.gwt.rpc" />
</static-files>

<!-- Configure java.util.logging -->
<system-properties>
<property name="java.util.logging.config.file" value="WEB-INF/logging.properties"/>
</system-properties>

<!--
HTTP Sessions are disabled by default. To enable HTTP sessions specify:

<sessions-enabled>true</sessions-enabled>

It's possible to reduce request latency by configuring your application to
asynchronously write HTTP session data to the datastore:

<async-session-persistence enabled="true" />

With this feature enabled, there is a very small chance your app will see
stale session data. For details, see
http://code.google.com/appengine/docs/java/config/appconfig.html#Enabling_Sessions


-->



</appengine-web-app>


what am i doing wrong ?




When I run the Android App Studio, the cell is the App is "installed" twice: There are two apps one called "SplashScreenActivity" and other "Doctor Quiz" (my app), the two are equal. If I uninstall one, the other also uninstalls.

Why does this happen? How do I "install" just my app? (DoctorQuiz)


AndroidManifest.xml



<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.morais.daniela.doctorquiz" >
<uses-permission android:name="android.permission.INTERNET"/>
<provider android:authorities="com.facebook.app.FacebookContentProviderXXXX"
android:name="com.facebook.FacebookContentProvider"
android:exported="true" />
<application
android:allowBackup="true"
android:icon="@drawable/medicine_box_icon2"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id"/>
<activity
android:name=".Activity.SplashScreenActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="@string/title_activity_splash_screen"
android:theme="@style/FullscreenTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Activity.QuestionsActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Activity.ResultActivity"
android:label="@string/title_activity_result" >
<activity android:name="com.facebook.FacebookActivity"
android:configChanges=
"keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:theme="@android:style/Theme.Translucent.NoTitleBar"
android:label="@string/app_name" />
</activity>

</application>

</manifest>


Screenshot

enter image description here




My clipping view isn't aligned in the y-axis. Its like the camera is looking a bit lower than it should be. The x-axis is completely fine, the edge of the scene lines up with the edge of the device screen. I thought that maybe I should rotate the 'mViewMatrix' first but my attempts at that have failed. What should I be doing?



@Override
public void onSurfaceChanged(GL10 unused, int width, int height) {

GLES20.glViewport(0, 0, width, height);// Sets the current view port to the new size.

float RATIO = (float) width / (float) height;

Matrix.orthoM(mProjectionMatrix, 0, -RATIO, RATIO, -1, 1, -1, 1);

}

@Override
public void onDrawFrame(GL10 unused) {

Matrix.setLookAtM(mViewMatrix, 0, 0, 0, -1, 0f, 0f, 0f, 0f, 1.0f, 0.0f);// Set the camera position (View matrix)
Matrix.multiplyMM(mMVPMatrix, 0, mProjectionMatrix, 0, mViewMatrix, 0);// Calculate the projection and view transformation



having a problem on handling runtime orientation changes on Android Application and saving all devices states. My app streams Video from an Ip cam, Im using pager Adapters. would anyone have any idea to handle this properly. thank you Guys




I want move a bitmap in the screen, but i can do it only horizontally, because if I do it vertically, the scroll of the view start and the movement of the bitmap disappears. I have


public boolean onTouchEvent(MotionEvent event)


method where in case MOVE I change the X and Y of the bitmap. Then in onDraw() method I paint the bitmap. The scroll are in xml. Inside of it are a layout and inside a View.


I would like when I touch, in case DOWN, if I touch the bitmap, disable the scroll, but I is in other place no.


Can someone help me? Thanks and regards.





Hi All, I am trying to play a song that is in remote server and is in this link. You also can check the song. but as per what i have coded the song is not getting played from the remote server.




Button b = (Button) findViewById(R.id.button1);
b.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
try{

mySong = new MediaPlayer();
mySong.setDataSource("http://www.hrupin.com/wp-content/uploads/mp3/testsong_20_sec.mp3");
mySong.setAudioStreamType(AudioManager.STREAM_MUSIC);
mySong.prepareAsync();
mySong.start();

}
catch(Exception ee){
TextView tv = (TextView) findViewById(R.id.textView1);
tv.setText(ee.getMessage());
}
finally{
mySong.reset();
mySong.release();
}
}
});