السلام عليكم و رحمه الله تعالى وبركاته
اخواني الكرام مرحبا بكم في مدونتي
٠٠٠عالم البرمجه ٠٠٠
للمبتدئين والمحترفين.
وتاكدو انشاء الله انني سابسط لكم كل ماتحتاجونه في ابسط
صوره من اكواد الجافا وغيرها الكثير من المعلومات.
_______________________
المرحله الاولى....
كيف تنشئ تطبيق يقوم بعرض لافته تحتوي على نص
عند بدء التشغيل؟
تستدعي المكتبه العامه وهي .
Toast
هاذه المكتبه مختصه بعرض لافته تحتوي على النصوص
import android.widget.Toast;
ثم نضعها في كود onStart
اي عند بدء التشغيل...
- >>>@Override
- >>> protected void onStart() {
- >>> super.onStart();
- >>>Toast.makeText(getApplicationContext(),"... اكتب النص المراد عرضه هناء.....",Toast.LENGTH_SHORT).show();
- }
هناء قد قمنا بعرض النص في بدايه اول مايتشغل التطبيق...
الامر بسيط جدا وهو انسخ والصق فقط..
___________________________
المرحله الثانيه......
كيف تصنع زر على التطبيق
وكيف تجعل له استجابه عند الضغط عليه..
وايضا عند الضغط عليه يقوم بعرض النص؟...
او اي شي اخر.
شاهد معي....👇
افتح اي من البرامج التي تقوم بصنع التطبيقات
مثل AIDE
او غيرها من البرامج الاخرى
لكن ساشرحها لكم في دروس اخرى
انشاء الله.
اولا تقوم بفتح ملف xml الموجود في
res/layout/activity _main.xml
>>>>>>
____________
اما الان ننتقل الى الملف الموجود في ملفات الجافا.
MainActivity.java
👇
package com.example.viewtext;
نلاحظ الان عند تشغيل التطبيق سوف تضهر لنا نافذه...
ويوجد بها الزر.... Button
وعند الضغط عليه سيقوم البرنامج بعرض النص الي اضفته في داخل الاكواد.
ويوجد ايضا الكثير من الاكواد التي تتميز بأنواعها
مثلا ارسال رساله لشخص ما
او الإتصال لشخص ما
سنشرحها في دروس اخرى...انتضروني
_______________
نشكركم على حسن المتابعه الرائعه نتمنى ان تنال اعجابكم
ونكون عند حسن ظنكم
مدونتي...
<<<< عالم البرمجه >>>>
الامر بسيط جدا وهو انسخ والصق فقط..
___________________________
المرحله الثانيه......
كيف تصنع زر على التطبيق
وكيف تجعل له استجابه عند الضغط عليه..
وايضا عند الضغط عليه يقوم بعرض النص؟...
او اي شي اخر.
شاهد معي....👇
افتح اي من البرامج التي تقوم بصنع التطبيقات
مثل AIDE
او غيرها من البرامج الاخرى
لكن ساشرحها لكم في دروس اخرى
انشاء الله.
اولا تقوم بفتح ملف xml الموجود في
res/layout/activity _main.xml
- >>> android:id="@+id/btn1"
- >>> . android:layout_height="wrap_content"
- >>> android:text="Short Toast"
- >>> android:backgroundTint="#6200EE"
- >>> android:textColor="#FFFFFF"
- >>> android:layout_marginTop="30dp"/>
>>>>>>
____________
اما الان ننتقل الى الملف الموجود في ملفات الجافا.
MainActivity.java
👇
package com.example.viewtext;
- >>> import android.app.Activity;
- >>> import android.os.Bundle;
- >>> import android.content.Context;
- >>> import android.os.Bundle;
- >>> import android.os.Environment;
- >>> import android.view.View;
- >>> import android.widget.Button;
- >>> import android.widget.Toast;
- >>> public class MainActivity extends Activity {
- >>> Button btn1;
- >>> @Override
- >>> protected void onCreate(Bundle savedInstanceState) {
- >>> super.onCreate(savedInstanceState);
- >>> setContentView(R.layout.layout_main);
- >>> btn1 = findViewById(R.id.btn1);
- >>> btn1.setOnClickListener(new View.OnClickListener() {
- >>> @Override
- >>> public void onClick(View v) {
- >>> Toast.makeText(getApplicationContext(), "....هناء اكتب النص المراد عرضه عند الضغط على الزر", Toast.LENGTH_SHORT).show();
- }
- });
- }
نلاحظ الان عند تشغيل التطبيق سوف تضهر لنا نافذه...
ويوجد بها الزر.... Button
وعند الضغط عليه سيقوم البرنامج بعرض النص الي اضفته في داخل الاكواد.
ويوجد ايضا الكثير من الاكواد التي تتميز بأنواعها
مثلا ارسال رساله لشخص ما
او الإتصال لشخص ما
سنشرحها في دروس اخرى...انتضروني
_______________
والان ننتقل الى كود جافا للرسم ثلاثي الابعاد
شاهد معي....
MainActivity.java
package rk.tutorial.surfaceviewanimation.example;
import android.opengl.GLSurfaceView;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.MenuItem;
import android.support.v4.app.NavUtils;
public class MainActivity extends Activity {
private GLSurfaceView mGLSurfaceView;
@Override
public void onCreate(Bundle savedInstanceState) {
@Override
protected void onResume() {
@Override
protected void onPause() {
}
import android.opengl.GLSurfaceView;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.MenuItem;
import android.support.v4.app.NavUtils;
public class MainActivity extends Activity {
private GLSurfaceView mGLSurfaceView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mGLSurfaceView = new GLSurfaceView(this);
mGLSurfaceView.setRenderer(new CubeRenderer(false));
setContentView(mGLSurfaceView);
}mGLSurfaceView = new GLSurfaceView(this);
mGLSurfaceView.setRenderer(new CubeRenderer(false));
setContentView(mGLSurfaceView);
@Override
protected void onResume() {
super.onResume();
mGLSurfaceView.onResume();
}mGLSurfaceView.onResume();
@Override
protected void onPause() {
super.onPause();
mGLSurfaceView.onPause();
}mGLSurfaceView.onPause();
}
Cube.java
package rk.tutorial.surfaceviewanimation.example;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.IntBuffer;
import javax.microedition.khronos.opengles.GL10;
class Cube {
public Cube() {
int one = 0x10000;
int vertices[] = { -one, -one, -one, one, -one, -one, one, one, -one, -one, one, -one, -one, -one, one, one, -one, one, one, one, one, -one, one, one, };
int colors[] = { 0, one, 0, one, one, 0, one, one, one, one, 0, one, 0, one, 0, one, 0, 0, one, one, one, 0, one, one, one, one, one, one, 0, one, one, one, };
byte indices[] = { 0, 4, 5, 0, 5, 1, 1, 5, 6, 1, 6, 2, 2, 6, 7, 2, 7, 3, 3, 7, 4, 3, 4, 0, 4, 7, 6, 4, 6, 5, 3, 0, 1, 3, 1, 2 };
ByteBuffer vbb = ByteBuffer.allocateDirect(vertices.length*4);
vbb.order(ByteOrder.nativeOrder());
mVertexBuffer = vbb.asIntBuffer();
mVertexBuffer.put(vertices);
mVertexBuffer.position(0);
ByteBuffer cbb = ByteBuffer.allocateDirect(colors.length*4);
cbb.order(ByteOrder.nativeOrder());
mColorBuffer = cbb.asIntBuffer();
mColorBuffer.put(colors);
mColorBuffer.position(0);
mIndexBuffer = ByteBuffer.allocateDirect(indices.length);
mIndexBuffer.put(indices);
mIndexBuffer.position(0);
}
public void draw(GL10 gl) {
private IntBuffer mVertexBuffer;
private IntBuffer mColorBuffer;
private ByteBuffer mIndexBuffer;
}
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.IntBuffer;
import javax.microedition.khronos.opengles.GL10;
class Cube {
public Cube() {
int one = 0x10000;
int vertices[] = { -one, -one, -one, one, -one, -one, one, one, -one, -one, one, -one, -one, -one, one, one, -one, one, one, one, one, -one, one, one, };
int colors[] = { 0, one, 0, one, one, 0, one, one, one, one, 0, one, 0, one, 0, one, 0, 0, one, one, one, 0, one, one, one, one, one, one, 0, one, one, one, };
byte indices[] = { 0, 4, 5, 0, 5, 1, 1, 5, 6, 1, 6, 2, 2, 6, 7, 2, 7, 3, 3, 7, 4, 3, 4, 0, 4, 7, 6, 4, 6, 5, 3, 0, 1, 3, 1, 2 };
ByteBuffer vbb = ByteBuffer.allocateDirect(vertices.length*4);
vbb.order(ByteOrder.nativeOrder());
mVertexBuffer = vbb.asIntBuffer();
mVertexBuffer.put(vertices);
mVertexBuffer.position(0);
ByteBuffer cbb = ByteBuffer.allocateDirect(colors.length*4);
cbb.order(ByteOrder.nativeOrder());
mColorBuffer = cbb.asIntBuffer();
mColorBuffer.put(colors);
mColorBuffer.position(0);
mIndexBuffer = ByteBuffer.allocateDirect(indices.length);
mIndexBuffer.put(indices);
mIndexBuffer.position(0);
}
public void draw(GL10 gl) {
gl.glFrontFace(GL10.GL_CW);
gl.glVertexPointer(3, GL10.GL_FIXED, 0, mVertexBuffer);
gl.glColorPointer(4, GL10.GL_FIXED, 0, mColorBuffer);
gl.glDrawElements(GL10.GL_TRIANGLES, 36, GL10.GL_UNSIGNED_BYTE, mIndexBuffer);
}gl.glVertexPointer(3, GL10.GL_FIXED, 0, mVertexBuffer);
gl.glColorPointer(4, GL10.GL_FIXED, 0, mColorBuffer);
gl.glDrawElements(GL10.GL_TRIANGLES, 36, GL10.GL_UNSIGNED_BYTE, mIndexBuffer);
private IntBuffer mVertexBuffer;
private IntBuffer mColorBuffer;
private ByteBuffer mIndexBuffer;
}
ثم الى ملف..
CubeRenderer.java
package rk.tutorial.surfaceviewanimation.example;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;
import android.opengl.GLSurfaceView;
class CubeRenderer implements GLSurfaceView.Renderer {
public CubeRenderer(boolean useTranslucentBackground) {
mTranslucentBackground = useTranslucentBackground;
mCube = new Cube();
}
public void onDrawFrame(GL10 gl) {
public void onSurfaceChanged(GL10 gl, int width, int height) {
private boolean mTranslucentBackground;
private Cube mCube;
private float mAngle;
}
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;
import android.opengl.GLSurfaceView;
class CubeRenderer implements GLSurfaceView.Renderer {
public CubeRenderer(boolean useTranslucentBackground) {
mTranslucentBackground = useTranslucentBackground;
mCube = new Cube();
}
public void onDrawFrame(GL10 gl) {
gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
gl.glMatrixMode(GL10.GL_MODELVIEW);
gl.glLoadIdentity();
gl.glTranslatef(0, 0, -3.0f);
gl.glRotatef(mAngle, 0, 1, 0);
gl.glRotatef(mAngle*0.25f, 1, 0, 0);
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
gl.glEnableClientState(GL10.GL_COLOR_ARRAY);
mCube.draw(gl);
gl.glRotatef(mAngle*2.0f, 0, 1, 1);
gl.glTranslatef(0.5f, 0.5f, 0.5f);
mCube.draw(gl);
mAngle += 1.2f;
}gl.glMatrixMode(GL10.GL_MODELVIEW);
gl.glLoadIdentity();
gl.glTranslatef(0, 0, -3.0f);
gl.glRotatef(mAngle, 0, 1, 0);
gl.glRotatef(mAngle*0.25f, 1, 0, 0);
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
gl.glEnableClientState(GL10.GL_COLOR_ARRAY);
mCube.draw(gl);
gl.glRotatef(mAngle*2.0f, 0, 1, 1);
gl.glTranslatef(0.5f, 0.5f, 0.5f);
mCube.draw(gl);
mAngle += 1.2f;
public void onSurfaceChanged(GL10 gl, int width, int height) {
gl.glViewport(0, 0, width, height);
float ratio = (float) width / height;
gl.glMatrixMode(GL10.GL_PROJECTION);
gl.glLoadIdentity();
gl.glFrustumf(-ratio, ratio, -1, 1, 1, 10);
} public void onSurfaceCreated(GL10 gl, EGLConfig config) {float ratio = (float) width / height;
gl.glMatrixMode(GL10.GL_PROJECTION);
gl.glLoadIdentity();
gl.glFrustumf(-ratio, ratio, -1, 1, 1, 10);
gl.glDisable(GL10.GL_DITHER);
gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_FASTEST);
if (mTranslucentBackground) {
gl.glClearColor(0,0,0,0);
} else {
gl.glClearColor(1,1,1,1);
}
gl.glEnable(GL10.GL_CULL_FACE);
gl.glShadeModel(GL10.GL_SMOOTH);
gl.glEnable(GL10.GL_DEPTH_TEST);
}gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_FASTEST);
if (mTranslucentBackground) {
gl.glClearColor(0,0,0,0);
} else {
gl.glClearColor(1,1,1,1);
}
gl.glEnable(GL10.GL_CULL_FACE);
gl.glShadeModel(GL10.GL_SMOOTH);
gl.glEnable(GL10.GL_DEPTH_TEST);
private boolean mTranslucentBackground;
private Cube mCube;
private float mAngle;
}
بصراحه يبدو جميل جدا..جربوه
نشكركم على حسن المتابعه الرائعه نتمنى ان تنال اعجابكم
ونكون عند حسن ظنكم
مدونتي...
<<<< عالم البرمجه >>>>
تعليقات
إرسال تعليق