diff --git a/Android/JatinGoyal/Advanced/NewsApp/.gitignore b/Android/JatinGoyal/Advanced/NewsApp/.gitignore new file mode 100644 index 00000000..aa724b77 --- /dev/null +++ b/Android/JatinGoyal/Advanced/NewsApp/.gitignore @@ -0,0 +1,15 @@ +*.iml +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store +/build +/captures +.externalNativeBuild +.cxx +local.properties diff --git a/Android/JatinGoyal/Advanced/NewsApp/.idea/.gitignore b/Android/JatinGoyal/Advanced/NewsApp/.idea/.gitignore new file mode 100644 index 00000000..26d33521 --- /dev/null +++ b/Android/JatinGoyal/Advanced/NewsApp/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/Android/JatinGoyal/Advanced/NewsApp/.idea/.name b/Android/JatinGoyal/Advanced/NewsApp/.idea/.name new file mode 100644 index 00000000..9da0a4e5 --- /dev/null +++ b/Android/JatinGoyal/Advanced/NewsApp/.idea/.name @@ -0,0 +1 @@ +News App \ No newline at end of file diff --git a/Android/JatinGoyal/Advanced/NewsApp/.idea/compiler.xml b/Android/JatinGoyal/Advanced/NewsApp/.idea/compiler.xml new file mode 100644 index 00000000..fb7f4a8a --- /dev/null +++ b/Android/JatinGoyal/Advanced/NewsApp/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Android/JatinGoyal/Advanced/NewsApp/.idea/gradle.xml b/Android/JatinGoyal/Advanced/NewsApp/.idea/gradle.xml new file mode 100644 index 00000000..5cd135a0 --- /dev/null +++ b/Android/JatinGoyal/Advanced/NewsApp/.idea/gradle.xml @@ -0,0 +1,20 @@ + + + + + + + \ No newline at end of file diff --git a/Android/JatinGoyal/Advanced/NewsApp/.idea/jarRepositories.xml b/Android/JatinGoyal/Advanced/NewsApp/.idea/jarRepositories.xml new file mode 100644 index 00000000..0380d8d3 --- /dev/null +++ b/Android/JatinGoyal/Advanced/NewsApp/.idea/jarRepositories.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Android/JatinGoyal/Advanced/NewsApp/.idea/misc.xml b/Android/JatinGoyal/Advanced/NewsApp/.idea/misc.xml new file mode 100644 index 00000000..6199cc2a --- /dev/null +++ b/Android/JatinGoyal/Advanced/NewsApp/.idea/misc.xml @@ -0,0 +1,9 @@ + + + + + + + + \ No newline at end of file diff --git a/Android/JatinGoyal/Advanced/NewsApp/.idea/runConfigurations.xml b/Android/JatinGoyal/Advanced/NewsApp/.idea/runConfigurations.xml new file mode 100644 index 00000000..797acea5 --- /dev/null +++ b/Android/JatinGoyal/Advanced/NewsApp/.idea/runConfigurations.xml @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file diff --git a/Android/JatinGoyal/Advanced/NewsApp/app/.gitignore b/Android/JatinGoyal/Advanced/NewsApp/app/.gitignore new file mode 100644 index 00000000..42afabfd --- /dev/null +++ b/Android/JatinGoyal/Advanced/NewsApp/app/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/Android/JatinGoyal/Advanced/NewsApp/app/build.gradle b/Android/JatinGoyal/Advanced/NewsApp/app/build.gradle new file mode 100644 index 00000000..78e7b0d4 --- /dev/null +++ b/Android/JatinGoyal/Advanced/NewsApp/app/build.gradle @@ -0,0 +1,44 @@ +plugins { + id 'com.android.application' +} + +android { + compileSdkVersion 30 + buildToolsVersion "30.0.3" + + defaultConfig { + applicationId "com.example.newsapp" + minSdkVersion 23 + targetSdkVersion 30 + versionCode 1 + versionName "1.0" + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } +} + +dependencies { + + implementation 'androidx.appcompat:appcompat:1.2.0' + implementation 'com.google.android.material:material:1.3.0' + implementation 'androidx.constraintlayout:constraintlayout:2.0.4' + implementation 'androidx.viewpager:viewpager:1.0.0' + testImplementation 'junit:junit:4.+' + androidTestImplementation 'androidx.test.ext:junit:1.1.2' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' + implementation 'com.koushikdutta.ion:ion:2.+' + implementation 'com.squareup.picasso:picasso:2.71828' + implementation 'com.squareup.retrofit2:retrofit:2.4.0' + implementation 'com.squareup.retrofit2:converter-gson:2.2.0' +} \ No newline at end of file diff --git a/Android/JatinGoyal/Advanced/NewsApp/app/proguard-rules.pro b/Android/JatinGoyal/Advanced/NewsApp/app/proguard-rules.pro new file mode 100644 index 00000000..481bb434 --- /dev/null +++ b/Android/JatinGoyal/Advanced/NewsApp/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/Android/JatinGoyal/Advanced/NewsApp/app/src/androidTest/java/com/example/newsapp/ExampleInstrumentedTest.java b/Android/JatinGoyal/Advanced/NewsApp/app/src/androidTest/java/com/example/newsapp/ExampleInstrumentedTest.java new file mode 100644 index 00000000..37bb3549 --- /dev/null +++ b/Android/JatinGoyal/Advanced/NewsApp/app/src/androidTest/java/com/example/newsapp/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package com.example.newsapp; + +import android.content.Context; + +import androidx.test.platform.app.InstrumentationRegistry; +import androidx.test.ext.junit.runners.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); + assertEquals("com.example.newsapp", appContext.getPackageName()); + } +} \ No newline at end of file diff --git a/Android/JatinGoyal/Advanced/NewsApp/app/src/main/AndroidManifest.xml b/Android/JatinGoyal/Advanced/NewsApp/app/src/main/AndroidManifest.xml new file mode 100644 index 00000000..6df2065e --- /dev/null +++ b/Android/JatinGoyal/Advanced/NewsApp/app/src/main/AndroidManifest.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Android/JatinGoyal/Advanced/NewsApp/app/src/main/java/com/example/newsapp/APIClient.java b/Android/JatinGoyal/Advanced/NewsApp/app/src/main/java/com/example/newsapp/APIClient.java new file mode 100644 index 00000000..7cc1d595 --- /dev/null +++ b/Android/JatinGoyal/Advanced/NewsApp/app/src/main/java/com/example/newsapp/APIClient.java @@ -0,0 +1,18 @@ +package com.example.newsapp; + +import retrofit2.Retrofit; +import retrofit2.converter.gson.GsonConverterFactory; + +public class APIClient { + public static final String BASE_URL = "https://newsapi.org/v2/"; + private static Retrofit retrofit = null; + public static Retrofit getClient() { + if (retrofit==null) { + retrofit = new Retrofit.Builder() + .baseUrl(BASE_URL) + .addConverterFactory(GsonConverterFactory.create()) + .build(); + } + return retrofit; + } +} \ No newline at end of file diff --git a/Android/JatinGoyal/Advanced/NewsApp/app/src/main/java/com/example/newsapp/APIInterface.java b/Android/JatinGoyal/Advanced/NewsApp/app/src/main/java/com/example/newsapp/APIInterface.java new file mode 100644 index 00000000..8ad9f7c1 --- /dev/null +++ b/Android/JatinGoyal/Advanced/NewsApp/app/src/main/java/com/example/newsapp/APIInterface.java @@ -0,0 +1,12 @@ +package com.example.newsapp; + +import retrofit2.Call; +import retrofit2.http.GET; +import retrofit2.http.Query; + +public interface APIInterface { + + @GET("top-headlines") + Call getCategoryNews(@Query("category") String category, @Query("language") String language, @Query("apiKey") String apiKey); + +} diff --git a/Android/JatinGoyal/Advanced/NewsApp/app/src/main/java/com/example/newsapp/Article.java b/Android/JatinGoyal/Advanced/NewsApp/app/src/main/java/com/example/newsapp/Article.java new file mode 100644 index 00000000..80ef27d7 --- /dev/null +++ b/Android/JatinGoyal/Advanced/NewsApp/app/src/main/java/com/example/newsapp/Article.java @@ -0,0 +1,62 @@ +package com.example.newsapp; + +import com.google.gson.annotations.SerializedName; + +public class Article { + @SerializedName("source") + private SourceModel source; + @SerializedName("author") + private String author; + @SerializedName("title") + private String title; + @SerializedName("description") + private String description; + @SerializedName("url") + private String url; + @SerializedName("urlToImage") + private String urlToImage; + @SerializedName("publishedAt") + private String publishedAt; + public SourceModel getSource() { + return source; + } + public void setSource(SourceModel source) { + this.source = source; + } + public String getAuthor() { + return author; + } + public void setAuthor(String author) { + this.author = author; + } + public String getTitle() { + return title; + } + public void setTitle(String title) { + this.title = title; + } + public String getDescription() { + return description; + } + public void setDescription(String description) { + this.description = description; + } + public String getUrl() { + return url; + } + public void setUrl(String url) { + this.url = url; + } + public String getUrlToImage() { + return urlToImage; + } + public void setUrlToImage(String urlToImage) { + this.urlToImage = urlToImage; + } + public String getPublishedAt() { + return publishedAt; + } + public void setPublishedAt(String publishedAt) { + this.publishedAt = publishedAt; + } +} diff --git a/Android/JatinGoyal/Advanced/NewsApp/app/src/main/java/com/example/newsapp/DetailsActivity.java b/Android/JatinGoyal/Advanced/NewsApp/app/src/main/java/com/example/newsapp/DetailsActivity.java new file mode 100644 index 00000000..701b3961 --- /dev/null +++ b/Android/JatinGoyal/Advanced/NewsApp/app/src/main/java/com/example/newsapp/DetailsActivity.java @@ -0,0 +1,43 @@ +package com.example.newsapp; + +import android.content.Intent; +import android.graphics.Color; +import android.graphics.drawable.ColorDrawable; +import android.os.Bundle; +import android.view.MenuItem; +import android.webkit.WebView; + +import androidx.appcompat.app.ActionBar; +import androidx.appcompat.app.AppCompatActivity; + +public class DetailsActivity extends AppCompatActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_details); + + WebView editWeb = findViewById(R.id.web); + Intent intent = getIntent(); + + String url = intent.getStringExtra("url"); + editWeb.loadUrl(url); + + ActionBar bar = getSupportActionBar(); + bar.setTitle("NewsApp"); + bar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("blue"))); + + bar.setDisplayHomeAsUpEnabled(true); + bar.setDisplayShowHomeEnabled(true); + + } + + public boolean onOptionsItemSelected(MenuItem item) { + if(item.getItemId() == android.R.id.home) + { + finish(); + } + + return super.onOptionsItemSelected(item); + } +} diff --git a/Android/JatinGoyal/Advanced/NewsApp/app/src/main/java/com/example/newsapp/ItemAdapter.java b/Android/JatinGoyal/Advanced/NewsApp/app/src/main/java/com/example/newsapp/ItemAdapter.java new file mode 100644 index 00000000..0cfb627e --- /dev/null +++ b/Android/JatinGoyal/Advanced/NewsApp/app/src/main/java/com/example/newsapp/ItemAdapter.java @@ -0,0 +1,105 @@ +package com.example.newsapp; + +import android.content.Context; +import android.content.Intent; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Button; +import android.widget.ImageView; +import android.widget.LinearLayout; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; + +import com.squareup.picasso.Picasso; + +import java.util.ArrayList; + +public class ItemAdapter extends RecyclerView.Adapter { + + + Context context; + + private final ArrayList items; + + public ItemAdapter(Context context, ArrayList items) { + this.context = context; + this.items = items; + + } + + @NonNull + @Override + public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) { + LayoutInflater inflater = LayoutInflater.from(this.context); + LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.news, null); + + return new ViewHolder(layout); + } + + @Override + public void onBindViewHolder(@NonNull ViewHolder holder, final int i) { + final ModelItems item = items.get(i); + + + + String title = item.getTitle(); + String author = item.getAuthor(); + String date = item.getDate(); + String urlToImage = item.getUrlToImage(); + final String url = item.getUrl(); + + + + if(title!=null) + holder.editTitle.setText(title); + if(author!=null) + holder.editauthor.setText("Author "+author); + if(date!=null) + holder.editdate.setText("published at: "+date); + if(urlToImage!=null) + Picasso.get().load(urlToImage).into(holder.editUrlImage); + + + holder.mybutton.setOnClickListener(new View.OnClickListener() { + + @Override + public void onClick(View v) { + + Intent intent = new Intent(context,DetailsActivity.class); + intent.putExtra("url",url); + context.startActivity(intent); + } + }); + + } + + + @Override + public int getItemCount() { + return items.size(); + } + + class ViewHolder extends RecyclerView.ViewHolder { + + TextView editTitle,editauthor,editdate; + ImageView editUrlImage; + Button mybutton; + ViewHolder(@NonNull View itemView) { + super(itemView); + + editTitle = itemView.findViewById(R.id.tittle1); + editUrlImage = itemView.findViewById(R.id.image1); + editauthor = itemView.findViewById(R.id.author); + editdate = itemView.findViewById(R.id.date); + mybutton = itemView.findViewById(R.id.details); + + + } + + } + + +} diff --git a/Android/JatinGoyal/Advanced/NewsApp/app/src/main/java/com/example/newsapp/MainActivity.java b/Android/JatinGoyal/Advanced/NewsApp/app/src/main/java/com/example/newsapp/MainActivity.java new file mode 100644 index 00000000..dd59abbe --- /dev/null +++ b/Android/JatinGoyal/Advanced/NewsApp/app/src/main/java/com/example/newsapp/MainActivity.java @@ -0,0 +1,55 @@ +package com.example.newsapp; + +import android.graphics.Color; +import android.graphics.drawable.ColorDrawable; +import android.os.Bundle; +import android.util.Log; + +import androidx.appcompat.app.ActionBar; +import androidx.appcompat.app.AppCompatActivity; +import androidx.viewpager.widget.ViewPager; + +import com.google.android.material.tabs.TabLayout; + +import java.util.List; + +import retrofit2.Call; +import retrofit2.Callback; +import retrofit2.Response; + + +public class MainActivity extends AppCompatActivity { + + private TabLayout TabLayout; + private ViewPager viewPager; + private MyPageAdapter adapter; + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + viewPager = findViewById(R.id.viewPager); + TabLayout = findViewById(R.id.tablayout); + + + adapter = new MyPageAdapter(getSupportFragmentManager()); + viewPager.setAdapter(adapter); + + TabLayout.setTabsFromPagerAdapter(adapter); + + + // to keep working together of tab layout and view pager + TabLayout.setupWithViewPager(viewPager); + viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(TabLayout)); + + + // for top bar of activity + ActionBar bar = getSupportActionBar(); + bar.setTitle("NewsApp"); + bar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("blue"))); + + } + + + +} \ No newline at end of file diff --git a/Android/JatinGoyal/Advanced/NewsApp/app/src/main/java/com/example/newsapp/ModelItems.java b/Android/JatinGoyal/Advanced/NewsApp/app/src/main/java/com/example/newsapp/ModelItems.java new file mode 100644 index 00000000..eb369164 --- /dev/null +++ b/Android/JatinGoyal/Advanced/NewsApp/app/src/main/java/com/example/newsapp/ModelItems.java @@ -0,0 +1,25 @@ +package com.example.newsapp; + +public class ModelItems { + + String title, author, date, urlToImage, url; + public ModelItems() {} + + public ModelItems(String title, String author, String date, String urlToImage, String url) { + this.title = title; + this.author = author; + this.date = date; + this.urlToImage = urlToImage; + this.url = url; } + + public String getTitle() {return title; } + public void setTitle(String title) {this.title = title; } + public String getAuthor() {return author;} + public void setAuthor(String author) {this.author = author;} + public String getDate() {return date;} + public void setDate(String date) {this.date = date;} + public String getUrlToImage() {return urlToImage;} + public void setUrlToImage(String urlToImage) {this.urlToImage = urlToImage;} + public String getUrl() {return url;} + public void setUrl(String url) {this.url = url;} +} diff --git a/Android/JatinGoyal/Advanced/NewsApp/app/src/main/java/com/example/newsapp/MyPageAdapter.java b/Android/JatinGoyal/Advanced/NewsApp/app/src/main/java/com/example/newsapp/MyPageAdapter.java new file mode 100644 index 00000000..39325890 --- /dev/null +++ b/Android/JatinGoyal/Advanced/NewsApp/app/src/main/java/com/example/newsapp/MyPageAdapter.java @@ -0,0 +1,54 @@ +package com.example.newsapp; + +import androidx.annotation.Nullable; +import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentManager; +import androidx.fragment.app.FragmentStatePagerAdapter; + +public class MyPageAdapter extends FragmentStatePagerAdapter { + + + + public MyPageAdapter(FragmentManager fm) { + + super(fm); + + } + + + @Override + public Fragment getItem(int i) { + // Log.e("pra"," "+i); + fragment frag = new fragment(i); + return frag; + } + + @Override + public int getCount() { + return 7; + } + + @Nullable + @Override + public CharSequence getPageTitle(int position) { + + if(position == 0) + return "General"; + else if(position == 2) + return "Sports"; + else if(position == 4) + return "Business"; + else if(position == 3) + return "Technology"; + else if(position == 1) + return "Entertainment"; + else if(position == 5) + return "Science"; + else if(position == 6) + return "Health"; + else + return "hello"; + + + } +} diff --git a/Android/JatinGoyal/Advanced/NewsApp/app/src/main/java/com/example/newsapp/ResponseModel.java b/Android/JatinGoyal/Advanced/NewsApp/app/src/main/java/com/example/newsapp/ResponseModel.java new file mode 100644 index 00000000..d748405f --- /dev/null +++ b/Android/JatinGoyal/Advanced/NewsApp/app/src/main/java/com/example/newsapp/ResponseModel.java @@ -0,0 +1,32 @@ +package com.example.newsapp; + +import com.google.gson.annotations.SerializedName; + +import java.util.List; + +public class ResponseModel { + @SerializedName("status") + private String status; + @SerializedName("totalResults") + private int totalResults; + @SerializedName("articles") + private List
articles = null; + public String getStatus() { + return status; + } + public void setStatus(String status) { + this.status = status; + } + public int getTotalResults() { + return totalResults; + } + public void setTotalResults(int totalResults) { + this.totalResults = totalResults; + } + public List
getArticles() { + return articles; + } + public void setArticles(List
articles) { + this.articles = articles; + } +} diff --git a/Android/JatinGoyal/Advanced/NewsApp/app/src/main/java/com/example/newsapp/SourceModel.java b/Android/JatinGoyal/Advanced/NewsApp/app/src/main/java/com/example/newsapp/SourceModel.java new file mode 100644 index 00000000..9af0dd84 --- /dev/null +++ b/Android/JatinGoyal/Advanced/NewsApp/app/src/main/java/com/example/newsapp/SourceModel.java @@ -0,0 +1,22 @@ +package com.example.newsapp; + +import com.google.gson.annotations.SerializedName; + +class SourceModel { + @SerializedName("id") + private String id; + @SerializedName("name") + private String name; + public String getId() { + return id; + } + public void setId(String id) { + this.id = id; + } + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } +} \ No newline at end of file diff --git a/Android/JatinGoyal/Advanced/NewsApp/app/src/main/java/com/example/newsapp/fragment.java b/Android/JatinGoyal/Advanced/NewsApp/app/src/main/java/com/example/newsapp/fragment.java new file mode 100644 index 00000000..7e32feb4 --- /dev/null +++ b/Android/JatinGoyal/Advanced/NewsApp/app/src/main/java/com/example/newsapp/fragment.java @@ -0,0 +1,117 @@ +package com.example.newsapp; + +import android.content.Context; +import android.os.Bundle; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.fragment.app.Fragment; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import com.koushikdutta.async.future.FutureCallback; +import com.koushikdutta.ion.Ion; + +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + +import retrofit2.Call; +import retrofit2.Callback; +import retrofit2.Response; + +public class fragment extends Fragment { + + + ArrayList items = new ArrayList <>(); + ItemAdapter adapter; + + Context context; + int pos; + public fragment() { + + } + + public fragment(int i) { + + this.pos = i; + } + + + @Nullable + @Override + public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { + + return inflater.inflate(R.layout.xmlfragment, container, false); + + } + + + @Override + public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + + final RecyclerView recyclerView = Objects.requireNonNull(getView()).findViewById(R.id.recyclerView); + + + final APIInterface apiService = APIClient.getClient().create(APIInterface.class); + Call call; + if (pos == 0) { + call = apiService.getCategoryNews("general", "en", "aae53caa51b2478db36695f18a36141b"); + } + else if(pos == 1){ + call = apiService.getCategoryNews("entertainment", "en", "aae53caa51b2478db36695f18a36141b"); + } + else if(pos == 2){ + call = apiService.getCategoryNews("sports", "en", "aae53caa51b2478db36695f18a36141b"); + } + else if(pos == 3){ + call = apiService.getCategoryNews("technology", "en", "aae53caa51b2478db36695f18a36141b"); + } + else if(pos == 4){ + call = apiService.getCategoryNews("business", "en", "aae53caa51b2478db36695f18a36141b"); + } + else if(pos == 5){ + call = apiService.getCategoryNews("science", "en", "aae53caa51b2478db36695f18a36141b"); + } + else{ + call = apiService.getCategoryNews("health", "en", "aae53caa51b2478db36695f18a36141b"); + } + + call.enqueue(new Callback() { + @Override + public void onResponse(Callcall, Response response) { + assert response.body() != null; + if(response.body().getStatus().equals("ok")) { + Log.d("main", "success"); + Log.d("main", String.valueOf(response.body().getTotalResults())); + List
articleList = response.body().getArticles(); + for(Article article: articleList) { + items.add(new ModelItems(article.getTitle(), article.getAuthor(), article.getPublishedAt(), article.getUrlToImage(), article.getUrl())); + } + + adapter = new ItemAdapter(getActivity(), items); + recyclerView.setAdapter(adapter); + + LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity()); + recyclerView.setLayoutManager(layoutManager); + } + } + @Override + public void onFailure(Callcall, Throwable t) { + Log.e("out", t.toString()); + } + }); + + } + + + + +} diff --git a/Android/JatinGoyal/Advanced/NewsApp/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/Android/JatinGoyal/Advanced/NewsApp/app/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 00000000..2b068d11 --- /dev/null +++ b/Android/JatinGoyal/Advanced/NewsApp/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/Android/JatinGoyal/Advanced/NewsApp/app/src/main/res/drawable/ic_launcher_background.xml b/Android/JatinGoyal/Advanced/NewsApp/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 00000000..07d5da9c --- /dev/null +++ b/Android/JatinGoyal/Advanced/NewsApp/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Android/JatinGoyal/Advanced/NewsApp/app/src/main/res/drawable/mybutton.xml b/Android/JatinGoyal/Advanced/NewsApp/app/src/main/res/drawable/mybutton.xml new file mode 100644 index 00000000..3685a27d --- /dev/null +++ b/Android/JatinGoyal/Advanced/NewsApp/app/src/main/res/drawable/mybutton.xml @@ -0,0 +1,12 @@ + + + + + + + + \ No newline at end of file diff --git a/Android/JatinGoyal/Advanced/NewsApp/app/src/main/res/layout/activity_details.xml b/Android/JatinGoyal/Advanced/NewsApp/app/src/main/res/layout/activity_details.xml new file mode 100644 index 00000000..db05a501 --- /dev/null +++ b/Android/JatinGoyal/Advanced/NewsApp/app/src/main/res/layout/activity_details.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Android/JatinGoyal/Advanced/NewsApp/app/src/main/res/layout/activity_main.xml b/Android/JatinGoyal/Advanced/NewsApp/app/src/main/res/layout/activity_main.xml new file mode 100644 index 00000000..ec0d5609 --- /dev/null +++ b/Android/JatinGoyal/Advanced/NewsApp/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Android/JatinGoyal/Advanced/NewsApp/app/src/main/res/layout/activity_my_news.xml b/Android/JatinGoyal/Advanced/NewsApp/app/src/main/res/layout/activity_my_news.xml new file mode 100644 index 00000000..49f3f34a --- /dev/null +++ b/Android/JatinGoyal/Advanced/NewsApp/app/src/main/res/layout/activity_my_news.xml @@ -0,0 +1,9 @@ + + + + \ No newline at end of file diff --git a/Android/JatinGoyal/Advanced/NewsApp/app/src/main/res/layout/news.xml b/Android/JatinGoyal/Advanced/NewsApp/app/src/main/res/layout/news.xml new file mode 100644 index 00000000..786ae335 --- /dev/null +++ b/Android/JatinGoyal/Advanced/NewsApp/app/src/main/res/layout/news.xml @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/HarmonyOS/Day1 Assingment/trainingApp/entry/src/main/resources/base/layout/login.xml b/HarmonyOS/Day1 Assingment/trainingApp/entry/src/main/resources/base/layout/login.xml new file mode 100644 index 00000000..e9c48c16 --- /dev/null +++ b/HarmonyOS/Day1 Assingment/trainingApp/entry/src/main/resources/base/layout/login.xml @@ -0,0 +1,15 @@ + + + + + + \ No newline at end of file diff --git a/HarmonyOS/Day1 Assingment/trainingApp/entry/src/main/resources/base/layout/signup.xml b/HarmonyOS/Day1 Assingment/trainingApp/entry/src/main/resources/base/layout/signup.xml new file mode 100644 index 00000000..877497ef --- /dev/null +++ b/HarmonyOS/Day1 Assingment/trainingApp/entry/src/main/resources/base/layout/signup.xml @@ -0,0 +1,15 @@ + + + + + + \ No newline at end of file diff --git a/HarmonyOS/Day1 Assingment/trainingApp/entry/src/main/resources/base/media/icon.png b/HarmonyOS/Day1 Assingment/trainingApp/entry/src/main/resources/base/media/icon.png new file mode 100644 index 00000000..ce307a88 Binary files /dev/null and b/HarmonyOS/Day1 Assingment/trainingApp/entry/src/main/resources/base/media/icon.png differ diff --git a/HarmonyOS/Day1 Assingment/trainingApp/entry/src/ohosTest/config.json b/HarmonyOS/Day1 Assingment/trainingApp/entry/src/ohosTest/config.json new file mode 100644 index 00000000..0e29531e --- /dev/null +++ b/HarmonyOS/Day1 Assingment/trainingApp/entry/src/ohosTest/config.json @@ -0,0 +1,41 @@ +{ + "app": { + "bundleName": "com.example.trainingapp", + "vendor": "example", + "version": { + "code": 1000000, + "name": "1.0.0" + }, + "apiVersion": { + "compatible": 5, + "target": 5, + "releaseType": "Release" + } + }, + "deviceConfig": {}, + "module": { + "package": "com.example.trainingapp", + "name": "testModule", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry_test", + "moduleType": "feature", + "installationFree": true + }, + "abilities": [ + { + "name": "decc.testkit.runner.EntryAbility", + "description": "Test Entry Ability", + "icon": "$media:icon", + "label": "$string:app_name", + "launchType": "standard", + "orientation": "landscape", + "visible": true, + "type": "page" + } + ] + } +} \ No newline at end of file diff --git a/HarmonyOS/Day1 Assingment/trainingApp/entry/src/ohosTest/java/com/example/trainingapp/ExampleOhosTest.java b/HarmonyOS/Day1 Assingment/trainingApp/entry/src/ohosTest/java/com/example/trainingapp/ExampleOhosTest.java new file mode 100644 index 00000000..3340a0d6 --- /dev/null +++ b/HarmonyOS/Day1 Assingment/trainingApp/entry/src/ohosTest/java/com/example/trainingapp/ExampleOhosTest.java @@ -0,0 +1,14 @@ +package com.example.trainingapp; + +import ohos.aafwk.ability.delegation.AbilityDelegatorRegistry; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class ExampleOhosTest { + @Test + public void testBundleName() { + final String actualBundleName = AbilityDelegatorRegistry.getArguments().getTestBundleName(); + assertEquals("com.example.trainingapp", actualBundleName); + } +} \ No newline at end of file diff --git a/HarmonyOS/Day1 Assingment/trainingApp/entry/src/test/java/com/example/trainingapp/ExampleTest.java b/HarmonyOS/Day1 Assingment/trainingApp/entry/src/test/java/com/example/trainingapp/ExampleTest.java new file mode 100644 index 00000000..b047cceb --- /dev/null +++ b/HarmonyOS/Day1 Assingment/trainingApp/entry/src/test/java/com/example/trainingapp/ExampleTest.java @@ -0,0 +1,9 @@ +package com.example.trainingapp; + +import org.junit.Test; + +public class ExampleTest { + @Test + public void onStart() { + } +} diff --git a/HarmonyOS/Day1 Assingment/trainingApp/gradle.properties b/HarmonyOS/Day1 Assingment/trainingApp/gradle.properties new file mode 100644 index 00000000..0daf1830 --- /dev/null +++ b/HarmonyOS/Day1 Assingment/trainingApp/gradle.properties @@ -0,0 +1,10 @@ +# Project-wide Gradle settings. +# IDE (e.g. DevEco Studio) users: +# Gradle settings configured through the IDE *will override* +# any settings specified in this file. +# For more details on how to configure your build environment visit +# http://www.gradle.org/docs/current/userguide/build_environment.html +# Specifies the JVM arguments used for the daemon process. +# The setting is particularly useful for tweaking memory settings. +# If the Chinese output is garbled, please configure the following parameter. +# org.gradle.jvmargs=-Dfile.encoding=GBK diff --git a/HarmonyOS/Day1 Assingment/trainingApp/gradle/wrapper/gradle-wrapper.jar b/HarmonyOS/Day1 Assingment/trainingApp/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 00000000..490fda85 Binary files /dev/null and b/HarmonyOS/Day1 Assingment/trainingApp/gradle/wrapper/gradle-wrapper.jar differ diff --git a/HarmonyOS/Day1 Assingment/trainingApp/gradle/wrapper/gradle-wrapper.properties b/HarmonyOS/Day1 Assingment/trainingApp/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 00000000..f59159e8 --- /dev/null +++ b/HarmonyOS/Day1 Assingment/trainingApp/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://repo.huaweicloud.com/gradle/gradle-6.3-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/HarmonyOS/Day1 Assingment/trainingApp/gradlew b/HarmonyOS/Day1 Assingment/trainingApp/gradlew new file mode 100644 index 00000000..2fe81a7d --- /dev/null +++ b/HarmonyOS/Day1 Assingment/trainingApp/gradlew @@ -0,0 +1,183 @@ +#!/usr/bin/env sh + +# +# Copyright 2015 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin or MSYS, switch paths to Windows format before running java +if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=`expr $i + 1` + done + case $i in + 0) set -- ;; + 1) set -- "$args0" ;; + 2) set -- "$args0" "$args1" ;; + 3) set -- "$args0" "$args1" "$args2" ;; + 4) set -- "$args0" "$args1" "$args2" "$args3" ;; + 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=`save "$@"` + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +exec "$JAVACMD" "$@" diff --git a/HarmonyOS/Day1 Assingment/trainingApp/gradlew.bat b/HarmonyOS/Day1 Assingment/trainingApp/gradlew.bat new file mode 100644 index 00000000..62bd9b9c --- /dev/null +++ b/HarmonyOS/Day1 Assingment/trainingApp/gradlew.bat @@ -0,0 +1,103 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windows variants + +if not "%OS%" == "Windows_NT" goto win9xME_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/HarmonyOS/Day1 Assingment/trainingApp/settings.gradle b/HarmonyOS/Day1 Assingment/trainingApp/settings.gradle new file mode 100644 index 00000000..4773db73 --- /dev/null +++ b/HarmonyOS/Day1 Assingment/trainingApp/settings.gradle @@ -0,0 +1 @@ +include ':entry' diff --git a/HarmonyOS/Day2 Assingment/trainingApp/.gitignore b/HarmonyOS/Day2 Assingment/trainingApp/.gitignore new file mode 100644 index 00000000..37a4eb8b --- /dev/null +++ b/HarmonyOS/Day2 Assingment/trainingApp/.gitignore @@ -0,0 +1,15 @@ +*.iml +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store +/build +/captures +.externalNativeBuild +/entry/.preview +.cxx diff --git a/HarmonyOS/Day2 Assingment/trainingApp/.idea/.gitignore b/HarmonyOS/Day2 Assingment/trainingApp/.idea/.gitignore new file mode 100644 index 00000000..26d33521 --- /dev/null +++ b/HarmonyOS/Day2 Assingment/trainingApp/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/HarmonyOS/Day2 Assingment/trainingApp/.idea/compiler.xml b/HarmonyOS/Day2 Assingment/trainingApp/.idea/compiler.xml new file mode 100644 index 00000000..61a9130c --- /dev/null +++ b/HarmonyOS/Day2 Assingment/trainingApp/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/HarmonyOS/Day2 Assingment/trainingApp/.idea/gradle.xml b/HarmonyOS/Day2 Assingment/trainingApp/.idea/gradle.xml new file mode 100644 index 00000000..b9090f42 --- /dev/null +++ b/HarmonyOS/Day2 Assingment/trainingApp/.idea/gradle.xml @@ -0,0 +1,22 @@ + + + + + + + \ No newline at end of file diff --git a/HarmonyOS/Day2 Assingment/trainingApp/.idea/jarRepositories.xml b/HarmonyOS/Day2 Assingment/trainingApp/.idea/jarRepositories.xml new file mode 100644 index 00000000..1dfcd020 --- /dev/null +++ b/HarmonyOS/Day2 Assingment/trainingApp/.idea/jarRepositories.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/HarmonyOS/Day2 Assingment/trainingApp/.idea/misc.xml b/HarmonyOS/Day2 Assingment/trainingApp/.idea/misc.xml new file mode 100644 index 00000000..58918f50 --- /dev/null +++ b/HarmonyOS/Day2 Assingment/trainingApp/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/HarmonyOS/Day2 Assingment/trainingApp/.idea/previewer/phone/phoneSettingConfig_1825807532.json b/HarmonyOS/Day2 Assingment/trainingApp/.idea/previewer/phone/phoneSettingConfig_1825807532.json new file mode 100644 index 00000000..f505e6b9 --- /dev/null +++ b/HarmonyOS/Day2 Assingment/trainingApp/.idea/previewer/phone/phoneSettingConfig_1825807532.json @@ -0,0 +1,25 @@ +{ + "setting": { + "1.0.1": { + "Language": { + "args": { + "Language": "zh-CN" + } + } + } + }, + "frontend": { + "1.0.0": { + "Resolution": { + "args": { + "Resolution": "360*780" + } + }, + "DeviceType": { + "args": { + "DeviceType": "phone" + } + } + } + } +} \ No newline at end of file diff --git a/HarmonyOS/Day2 Assingment/trainingApp/.idea/previewer/previewConfig.json b/HarmonyOS/Day2 Assingment/trainingApp/.idea/previewer/previewConfig.json new file mode 100644 index 00000000..0c811855 --- /dev/null +++ b/HarmonyOS/Day2 Assingment/trainingApp/.idea/previewer/previewConfig.json @@ -0,0 +1,9 @@ +{ + "1.0.0": { + "LastPreviewDevice": { + "C:\\Users\\jjati\\DevEcoStudioProjects\\trainingApp\\entry": [ + "phone" + ] + } + } +} \ No newline at end of file diff --git a/HarmonyOS/Day2 Assingment/trainingApp/build.gradle b/HarmonyOS/Day2 Assingment/trainingApp/build.gradle new file mode 100644 index 00000000..1dc510ff --- /dev/null +++ b/HarmonyOS/Day2 Assingment/trainingApp/build.gradle @@ -0,0 +1,37 @@ +// Top-level build file where you can add configuration options common to all sub-projects/modules. +apply plugin: 'com.huawei.ohos.app' + +ohos { + compileSdkVersion 5 + defaultConfig { + compatibleSdkVersion 5 + } +} + +buildscript { + repositories { + maven { + url 'https://repo.huaweicloud.com/repository/maven/' + } + maven { + url 'https://developer.huawei.com/repo/' + } + jcenter() + } + dependencies { + classpath 'com.huawei.ohos:hap:2.4.2.7' + classpath 'com.huawei.ohos:decctest:1.0.0.7' + } +} + +allprojects { + repositories { + maven { + url 'https://repo.huaweicloud.com/repository/maven/' + } + maven { + url 'https://developer.huawei.com/repo/' + } + jcenter() + } +} diff --git a/HarmonyOS/Day2 Assingment/trainingApp/entry/.gitignore b/HarmonyOS/Day2 Assingment/trainingApp/entry/.gitignore new file mode 100644 index 00000000..796b96d1 --- /dev/null +++ b/HarmonyOS/Day2 Assingment/trainingApp/entry/.gitignore @@ -0,0 +1 @@ +/build diff --git a/HarmonyOS/Day2 Assingment/trainingApp/entry/build.gradle b/HarmonyOS/Day2 Assingment/trainingApp/entry/build.gradle new file mode 100644 index 00000000..752a0370 --- /dev/null +++ b/HarmonyOS/Day2 Assingment/trainingApp/entry/build.gradle @@ -0,0 +1,26 @@ +apply plugin: 'com.huawei.ohos.hap' +apply plugin: 'com.huawei.ohos.decctest' +ohos { + compileSdkVersion 5 + defaultConfig { + compatibleSdkVersion 5 + } + buildTypes { + release { + proguardOpt { + proguardEnabled false + rulesFiles 'proguard-rules.pro' + } + } + } + +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar', '*.har']) + testImplementation 'junit:junit:4.13' + ohosTestImplementation 'com.huawei.ohos.testkit:runner:1.0.0.100' +} +decc { + supportType = ['html','xml'] +} diff --git a/HarmonyOS/Day2 Assingment/trainingApp/entry/proguard-rules.pro b/HarmonyOS/Day2 Assingment/trainingApp/entry/proguard-rules.pro new file mode 100644 index 00000000..f7666e47 --- /dev/null +++ b/HarmonyOS/Day2 Assingment/trainingApp/entry/proguard-rules.pro @@ -0,0 +1 @@ +# config module specific ProGuard rules here. \ No newline at end of file diff --git a/HarmonyOS/Day2 Assingment/trainingApp/entry/src/main/config.json b/HarmonyOS/Day2 Assingment/trainingApp/entry/src/main/config.json new file mode 100644 index 00000000..89337b4d --- /dev/null +++ b/HarmonyOS/Day2 Assingment/trainingApp/entry/src/main/config.json @@ -0,0 +1,49 @@ +{ + "app": { + "bundleName": "com.example.trainingapp", + "vendor": "example", + "version": { + "code": 1000000, + "name": "1.0.0" + }, + "apiVersion": { + "compatible": 5, + "target": 5, + "releaseType": "Release" + } + }, + "deviceConfig": {}, + "module": { + "package": "com.example.trainingapp", + "name": ".MyApplication", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry", + "moduleType": "entry" + }, + "abilities": [ + { + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "orientation": "unspecified", + "name": "com.example.trainingapp.MainAbility", + "icon": "$media:icon", + "description": "$string:mainability_description", + "label": "$string:app_name", + "type": "page", + "launchType": "standard" + } + ] + } +} \ No newline at end of file diff --git a/HarmonyOS/Day2 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/MainAbility.java b/HarmonyOS/Day2 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/MainAbility.java new file mode 100644 index 00000000..bf407ed6 --- /dev/null +++ b/HarmonyOS/Day2 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/MainAbility.java @@ -0,0 +1,13 @@ +package com.example.trainingapp; + +import com.example.trainingapp.slice.MainAbilitySlice; +import ohos.aafwk.ability.Ability; +import ohos.aafwk.content.Intent; + +public class MainAbility extends Ability { + @Override + public void onStart(Intent intent) { + super.onStart(intent); + super.setMainRoute(MainAbilitySlice.class.getName()); + } +} diff --git a/HarmonyOS/Day2 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/MyApplication.java b/HarmonyOS/Day2 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/MyApplication.java new file mode 100644 index 00000000..ecf61daa --- /dev/null +++ b/HarmonyOS/Day2 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/MyApplication.java @@ -0,0 +1,10 @@ +package com.example.trainingapp; + +import ohos.aafwk.ability.AbilityPackage; + +public class MyApplication extends AbilityPackage { + @Override + public void onInitialize() { + super.onInitialize(); + } +} diff --git a/HarmonyOS/Day2 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/slice/LoginSlice.java b/HarmonyOS/Day2 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/slice/LoginSlice.java new file mode 100644 index 00000000..4fc101c5 --- /dev/null +++ b/HarmonyOS/Day2 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/slice/LoginSlice.java @@ -0,0 +1,13 @@ +package com.example.trainingapp.slice; + +import ohos.aafwk.ability.AbilitySlice; +import ohos.aafwk.content.Intent; +import com.example.trainingapp.ResourceTable; + +public class LoginSlice extends AbilitySlice { + @Override + protected void onStart(Intent intent){ + super.onStart(intent); + super.setUIContent(ResourceTable.Layout_login); + } +} diff --git a/HarmonyOS/Day2 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/slice/MainAbilitySlice.java b/HarmonyOS/Day2 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/slice/MainAbilitySlice.java new file mode 100644 index 00000000..2a8fbb41 --- /dev/null +++ b/HarmonyOS/Day2 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/slice/MainAbilitySlice.java @@ -0,0 +1,30 @@ +package com.example.trainingapp.slice; + +import com.example.trainingapp.ResourceTable; +import ohos.aafwk.ability.AbilitySlice; +import ohos.aafwk.content.Intent; +import ohos.agp.components.Button; + +public class MainAbilitySlice extends AbilitySlice { + @Override + public void onStart(Intent intent) { + super.onStart(intent); + super.setUIContent(ResourceTable.Layout_ability_main); + + Button bt1 = (Button) findComponentById(ResourceTable.Id_log); + Button bt2 = (Button) findComponentById(ResourceTable.Id_sign); + + bt1.setClickedListener(listener -> present(new LoginSlice(), new Intent())); + bt2.setClickedListener(listener -> present(new SignupSlice(), new Intent())); + } + + @Override + public void onActive() { + super.onActive(); + } + + @Override + public void onForeground(Intent intent) { + super.onForeground(intent); + } +} diff --git a/HarmonyOS/Day2 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/slice/SignupSlice.java b/HarmonyOS/Day2 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/slice/SignupSlice.java new file mode 100644 index 00000000..368ce272 --- /dev/null +++ b/HarmonyOS/Day2 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/slice/SignupSlice.java @@ -0,0 +1,114 @@ +package com.example.trainingapp.slice; + +import ohos.aafwk.ability.AbilitySlice; +import ohos.aafwk.content.Intent; +import com.example.trainingapp.ResourceTable; +import ohos.agp.components.*; +import java.util.regex.Pattern; + +public class SignupSlice extends AbilitySlice { + TextField firstName, lastName, email, password, mobile; + Text firstError, lastError, emailError, passError, mobileError, radioError; + RadioButton maleRadio,femaleRadio; + Button signupBtn; + @Override + protected void onStart(Intent intent){ + super.onStart(intent); + super.setUIContent(ResourceTable.Layout_signup); + + firstName = (TextField) findComponentById(ResourceTable.Id_first_name); + lastName = (TextField) findComponentById((ResourceTable.Id_last_name)); + email = (TextField) findComponentById(ResourceTable.Id_email); + password = (TextField) findComponentById(ResourceTable.Id_password); + mobile = (TextField) findComponentById(ResourceTable.Id_mobile); + + maleRadio = (RadioButton) findComponentById(ResourceTable.Id_male); + femaleRadio = (RadioButton) findComponentById(ResourceTable.Id_female); + + firstError = (Text) findComponentById(ResourceTable.Id_firstError); + lastError = (Text) findComponentById(ResourceTable.Id_lastError); + emailError = (Text) findComponentById(ResourceTable.Id_emailError); + passError = (Text) findComponentById(ResourceTable.Id_passwordError); + mobileError = (Text) findComponentById(ResourceTable.Id_mobileError); + radioError = (Text) findComponentById(ResourceTable.Id_radioError); + + signupBtn =(Button) findComponentById(ResourceTable.Id_signup); + + signupBtn.setClickedListener(new Component.ClickedListener() { + @Override + public void onClick(Component component) { + checkValidity(); + } + }); + + } + public boolean isNameValid(TextField name){ + String str = name.getText(); + String regex = "[a-zA-Z]+"; + Pattern p = Pattern.compile(regex); + + return p.matcher(str).matches(); + } + + public boolean isEmailValid(TextField email){ + String str = email.getText(); + String regex = ".+@.+\\..+"; + Pattern p = Pattern.compile(regex); + + return p.matcher(str).matches(); + } + + public boolean isPhoneValid(TextField mobile){ + String str = mobile.getText(); + String regex = "[1-9][0-9]{9}"; + Pattern p = Pattern.compile(regex); + + return p.matcher(str).matches(); + } + + public boolean isPassValid(TextField password){ + String str = password.getText(); + String regex = ".{5,}"; + Pattern p = Pattern.compile(regex); + return p.matcher(str).matches(); + } + + public void checkValidity(){ + if(firstName.getText() == null || firstName.getText().isEmpty() || !isNameValid(firstName)){ + firstError.setVisibility(Component.VISIBLE); + } + else{ + firstError.setVisibility(Component.INVISIBLE); + } + if(lastName.getText() == null || lastName.getText().isEmpty() || !isNameValid(lastName)){ + lastError.setVisibility(Component.VISIBLE); + } + else{ + lastError.setVisibility(Component.INVISIBLE); + } + if(email.getText() == null || email.getText().isEmpty() || !isEmailValid(email)){ + emailError.setVisibility(Component.VISIBLE); + } + else{ + emailError.setVisibility(Component.INVISIBLE); + } + if(mobile.getText() == null || mobile.getText().isEmpty() || !isPhoneValid(mobile)){ + mobileError.setVisibility(Component.VISIBLE); + } + else{ + mobileError.setVisibility(Component.INVISIBLE); + } + if(password.getText() == null || password.getText().isEmpty() || !isPassValid(password)){ + passError.setVisibility(Component.VISIBLE); + } + else{ + passError.setVisibility(Component.INVISIBLE); + } + if(!maleRadio.isChecked() && !femaleRadio.isChecked()){ + radioError.setVisibility(Component.VISIBLE); + } + else{ + radioError.setVisibility(Component.INVISIBLE); + } + } +} diff --git a/HarmonyOS/Day2 Assingment/trainingApp/entry/src/main/resources/base/element/string.json b/HarmonyOS/Day2 Assingment/trainingApp/entry/src/main/resources/base/element/string.json new file mode 100644 index 00000000..fb02a338 --- /dev/null +++ b/HarmonyOS/Day2 Assingment/trainingApp/entry/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "app_name", + "value": "trainingApp" + }, + { + "name": "mainability_description", + "value": "Java_Phone_Empty Feature Ability" + }, + { + "name": "mainability_HelloWorld", + "value": "Hello World" + } + ] +} \ No newline at end of file diff --git a/HarmonyOS/Day2 Assingment/trainingApp/entry/src/main/resources/base/graphic/background_ability_main.xml b/HarmonyOS/Day2 Assingment/trainingApp/entry/src/main/resources/base/graphic/background_ability_main.xml new file mode 100644 index 00000000..c0c0a3df --- /dev/null +++ b/HarmonyOS/Day2 Assingment/trainingApp/entry/src/main/resources/base/graphic/background_ability_main.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/HarmonyOS/Day2 Assingment/trainingApp/entry/src/main/resources/base/layout/ability_main.xml b/HarmonyOS/Day2 Assingment/trainingApp/entry/src/main/resources/base/layout/ability_main.xml new file mode 100644 index 00000000..9440f26f --- /dev/null +++ b/HarmonyOS/Day2 Assingment/trainingApp/entry/src/main/resources/base/layout/ability_main.xml @@ -0,0 +1,51 @@ + + + + + + + + \ No newline at end of file diff --git a/HarmonyOS/Day2 Assingment/trainingApp/entry/src/main/resources/base/layout/login.xml b/HarmonyOS/Day2 Assingment/trainingApp/entry/src/main/resources/base/layout/login.xml new file mode 100644 index 00000000..f9fe34fb --- /dev/null +++ b/HarmonyOS/Day2 Assingment/trainingApp/entry/src/main/resources/base/layout/login.xml @@ -0,0 +1,73 @@ + + + + + + + + + + \ No newline at end of file diff --git a/HarmonyOS/Day2 Assingment/trainingApp/entry/src/main/resources/base/layout/signup.xml b/HarmonyOS/Day2 Assingment/trainingApp/entry/src/main/resources/base/layout/signup.xml new file mode 100644 index 00000000..30314ef4 --- /dev/null +++ b/HarmonyOS/Day2 Assingment/trainingApp/entry/src/main/resources/base/layout/signup.xml @@ -0,0 +1,190 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/HarmonyOS/Day2 Assingment/trainingApp/entry/src/main/resources/base/media/icon.png b/HarmonyOS/Day2 Assingment/trainingApp/entry/src/main/resources/base/media/icon.png new file mode 100644 index 00000000..ce307a88 Binary files /dev/null and b/HarmonyOS/Day2 Assingment/trainingApp/entry/src/main/resources/base/media/icon.png differ diff --git a/HarmonyOS/Day2 Assingment/trainingApp/entry/src/ohosTest/config.json b/HarmonyOS/Day2 Assingment/trainingApp/entry/src/ohosTest/config.json new file mode 100644 index 00000000..0e29531e --- /dev/null +++ b/HarmonyOS/Day2 Assingment/trainingApp/entry/src/ohosTest/config.json @@ -0,0 +1,41 @@ +{ + "app": { + "bundleName": "com.example.trainingapp", + "vendor": "example", + "version": { + "code": 1000000, + "name": "1.0.0" + }, + "apiVersion": { + "compatible": 5, + "target": 5, + "releaseType": "Release" + } + }, + "deviceConfig": {}, + "module": { + "package": "com.example.trainingapp", + "name": "testModule", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry_test", + "moduleType": "feature", + "installationFree": true + }, + "abilities": [ + { + "name": "decc.testkit.runner.EntryAbility", + "description": "Test Entry Ability", + "icon": "$media:icon", + "label": "$string:app_name", + "launchType": "standard", + "orientation": "landscape", + "visible": true, + "type": "page" + } + ] + } +} \ No newline at end of file diff --git a/HarmonyOS/Day2 Assingment/trainingApp/entry/src/ohosTest/java/com/example/trainingapp/ExampleOhosTest.java b/HarmonyOS/Day2 Assingment/trainingApp/entry/src/ohosTest/java/com/example/trainingapp/ExampleOhosTest.java new file mode 100644 index 00000000..3340a0d6 --- /dev/null +++ b/HarmonyOS/Day2 Assingment/trainingApp/entry/src/ohosTest/java/com/example/trainingapp/ExampleOhosTest.java @@ -0,0 +1,14 @@ +package com.example.trainingapp; + +import ohos.aafwk.ability.delegation.AbilityDelegatorRegistry; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class ExampleOhosTest { + @Test + public void testBundleName() { + final String actualBundleName = AbilityDelegatorRegistry.getArguments().getTestBundleName(); + assertEquals("com.example.trainingapp", actualBundleName); + } +} \ No newline at end of file diff --git a/HarmonyOS/Day2 Assingment/trainingApp/entry/src/test/java/com/example/trainingapp/ExampleTest.java b/HarmonyOS/Day2 Assingment/trainingApp/entry/src/test/java/com/example/trainingapp/ExampleTest.java new file mode 100644 index 00000000..b047cceb --- /dev/null +++ b/HarmonyOS/Day2 Assingment/trainingApp/entry/src/test/java/com/example/trainingapp/ExampleTest.java @@ -0,0 +1,9 @@ +package com.example.trainingapp; + +import org.junit.Test; + +public class ExampleTest { + @Test + public void onStart() { + } +} diff --git a/HarmonyOS/Day2 Assingment/trainingApp/gradle.properties b/HarmonyOS/Day2 Assingment/trainingApp/gradle.properties new file mode 100644 index 00000000..0daf1830 --- /dev/null +++ b/HarmonyOS/Day2 Assingment/trainingApp/gradle.properties @@ -0,0 +1,10 @@ +# Project-wide Gradle settings. +# IDE (e.g. DevEco Studio) users: +# Gradle settings configured through the IDE *will override* +# any settings specified in this file. +# For more details on how to configure your build environment visit +# http://www.gradle.org/docs/current/userguide/build_environment.html +# Specifies the JVM arguments used for the daemon process. +# The setting is particularly useful for tweaking memory settings. +# If the Chinese output is garbled, please configure the following parameter. +# org.gradle.jvmargs=-Dfile.encoding=GBK diff --git a/HarmonyOS/Day2 Assingment/trainingApp/gradle/wrapper/gradle-wrapper.jar b/HarmonyOS/Day2 Assingment/trainingApp/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 00000000..490fda85 Binary files /dev/null and b/HarmonyOS/Day2 Assingment/trainingApp/gradle/wrapper/gradle-wrapper.jar differ diff --git a/HarmonyOS/Day2 Assingment/trainingApp/gradle/wrapper/gradle-wrapper.properties b/HarmonyOS/Day2 Assingment/trainingApp/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 00000000..f59159e8 --- /dev/null +++ b/HarmonyOS/Day2 Assingment/trainingApp/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://repo.huaweicloud.com/gradle/gradle-6.3-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/HarmonyOS/Day2 Assingment/trainingApp/gradlew b/HarmonyOS/Day2 Assingment/trainingApp/gradlew new file mode 100644 index 00000000..2fe81a7d --- /dev/null +++ b/HarmonyOS/Day2 Assingment/trainingApp/gradlew @@ -0,0 +1,183 @@ +#!/usr/bin/env sh + +# +# Copyright 2015 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin or MSYS, switch paths to Windows format before running java +if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=`expr $i + 1` + done + case $i in + 0) set -- ;; + 1) set -- "$args0" ;; + 2) set -- "$args0" "$args1" ;; + 3) set -- "$args0" "$args1" "$args2" ;; + 4) set -- "$args0" "$args1" "$args2" "$args3" ;; + 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=`save "$@"` + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +exec "$JAVACMD" "$@" diff --git a/HarmonyOS/Day2 Assingment/trainingApp/gradlew.bat b/HarmonyOS/Day2 Assingment/trainingApp/gradlew.bat new file mode 100644 index 00000000..62bd9b9c --- /dev/null +++ b/HarmonyOS/Day2 Assingment/trainingApp/gradlew.bat @@ -0,0 +1,103 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windows variants + +if not "%OS%" == "Windows_NT" goto win9xME_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/HarmonyOS/Day2 Assingment/trainingApp/settings.gradle b/HarmonyOS/Day2 Assingment/trainingApp/settings.gradle new file mode 100644 index 00000000..4773db73 --- /dev/null +++ b/HarmonyOS/Day2 Assingment/trainingApp/settings.gradle @@ -0,0 +1 @@ +include ':entry' diff --git a/HarmonyOS/Day3 Assingment/trainingApp/.gitignore b/HarmonyOS/Day3 Assingment/trainingApp/.gitignore new file mode 100644 index 00000000..37a4eb8b --- /dev/null +++ b/HarmonyOS/Day3 Assingment/trainingApp/.gitignore @@ -0,0 +1,15 @@ +*.iml +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store +/build +/captures +.externalNativeBuild +/entry/.preview +.cxx diff --git a/HarmonyOS/Day3 Assingment/trainingApp/.idea/.gitignore b/HarmonyOS/Day3 Assingment/trainingApp/.idea/.gitignore new file mode 100644 index 00000000..26d33521 --- /dev/null +++ b/HarmonyOS/Day3 Assingment/trainingApp/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/HarmonyOS/Day3 Assingment/trainingApp/.idea/compiler.xml b/HarmonyOS/Day3 Assingment/trainingApp/.idea/compiler.xml new file mode 100644 index 00000000..61a9130c --- /dev/null +++ b/HarmonyOS/Day3 Assingment/trainingApp/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/HarmonyOS/Day3 Assingment/trainingApp/.idea/gradle.xml b/HarmonyOS/Day3 Assingment/trainingApp/.idea/gradle.xml new file mode 100644 index 00000000..b9090f42 --- /dev/null +++ b/HarmonyOS/Day3 Assingment/trainingApp/.idea/gradle.xml @@ -0,0 +1,22 @@ + + + + + + + \ No newline at end of file diff --git a/HarmonyOS/Day3 Assingment/trainingApp/.idea/jarRepositories.xml b/HarmonyOS/Day3 Assingment/trainingApp/.idea/jarRepositories.xml new file mode 100644 index 00000000..1dfcd020 --- /dev/null +++ b/HarmonyOS/Day3 Assingment/trainingApp/.idea/jarRepositories.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/HarmonyOS/Day3 Assingment/trainingApp/.idea/misc.xml b/HarmonyOS/Day3 Assingment/trainingApp/.idea/misc.xml new file mode 100644 index 00000000..58918f50 --- /dev/null +++ b/HarmonyOS/Day3 Assingment/trainingApp/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/HarmonyOS/Day3 Assingment/trainingApp/.idea/previewer/phone/phoneSettingConfig_1825807532.json b/HarmonyOS/Day3 Assingment/trainingApp/.idea/previewer/phone/phoneSettingConfig_1825807532.json new file mode 100644 index 00000000..f505e6b9 --- /dev/null +++ b/HarmonyOS/Day3 Assingment/trainingApp/.idea/previewer/phone/phoneSettingConfig_1825807532.json @@ -0,0 +1,25 @@ +{ + "setting": { + "1.0.1": { + "Language": { + "args": { + "Language": "zh-CN" + } + } + } + }, + "frontend": { + "1.0.0": { + "Resolution": { + "args": { + "Resolution": "360*780" + } + }, + "DeviceType": { + "args": { + "DeviceType": "phone" + } + } + } + } +} \ No newline at end of file diff --git a/HarmonyOS/Day3 Assingment/trainingApp/.idea/previewer/previewConfig.json b/HarmonyOS/Day3 Assingment/trainingApp/.idea/previewer/previewConfig.json new file mode 100644 index 00000000..0c811855 --- /dev/null +++ b/HarmonyOS/Day3 Assingment/trainingApp/.idea/previewer/previewConfig.json @@ -0,0 +1,9 @@ +{ + "1.0.0": { + "LastPreviewDevice": { + "C:\\Users\\jjati\\DevEcoStudioProjects\\trainingApp\\entry": [ + "phone" + ] + } + } +} \ No newline at end of file diff --git a/HarmonyOS/Day3 Assingment/trainingApp/build.gradle b/HarmonyOS/Day3 Assingment/trainingApp/build.gradle new file mode 100644 index 00000000..1dc510ff --- /dev/null +++ b/HarmonyOS/Day3 Assingment/trainingApp/build.gradle @@ -0,0 +1,37 @@ +// Top-level build file where you can add configuration options common to all sub-projects/modules. +apply plugin: 'com.huawei.ohos.app' + +ohos { + compileSdkVersion 5 + defaultConfig { + compatibleSdkVersion 5 + } +} + +buildscript { + repositories { + maven { + url 'https://repo.huaweicloud.com/repository/maven/' + } + maven { + url 'https://developer.huawei.com/repo/' + } + jcenter() + } + dependencies { + classpath 'com.huawei.ohos:hap:2.4.2.7' + classpath 'com.huawei.ohos:decctest:1.0.0.7' + } +} + +allprojects { + repositories { + maven { + url 'https://repo.huaweicloud.com/repository/maven/' + } + maven { + url 'https://developer.huawei.com/repo/' + } + jcenter() + } +} diff --git a/HarmonyOS/Day3 Assingment/trainingApp/entry/.gitignore b/HarmonyOS/Day3 Assingment/trainingApp/entry/.gitignore new file mode 100644 index 00000000..796b96d1 --- /dev/null +++ b/HarmonyOS/Day3 Assingment/trainingApp/entry/.gitignore @@ -0,0 +1 @@ +/build diff --git a/HarmonyOS/Day3 Assingment/trainingApp/entry/build.gradle b/HarmonyOS/Day3 Assingment/trainingApp/entry/build.gradle new file mode 100644 index 00000000..752a0370 --- /dev/null +++ b/HarmonyOS/Day3 Assingment/trainingApp/entry/build.gradle @@ -0,0 +1,26 @@ +apply plugin: 'com.huawei.ohos.hap' +apply plugin: 'com.huawei.ohos.decctest' +ohos { + compileSdkVersion 5 + defaultConfig { + compatibleSdkVersion 5 + } + buildTypes { + release { + proguardOpt { + proguardEnabled false + rulesFiles 'proguard-rules.pro' + } + } + } + +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar', '*.har']) + testImplementation 'junit:junit:4.13' + ohosTestImplementation 'com.huawei.ohos.testkit:runner:1.0.0.100' +} +decc { + supportType = ['html','xml'] +} diff --git a/HarmonyOS/Day3 Assingment/trainingApp/entry/proguard-rules.pro b/HarmonyOS/Day3 Assingment/trainingApp/entry/proguard-rules.pro new file mode 100644 index 00000000..f7666e47 --- /dev/null +++ b/HarmonyOS/Day3 Assingment/trainingApp/entry/proguard-rules.pro @@ -0,0 +1 @@ +# config module specific ProGuard rules here. \ No newline at end of file diff --git a/HarmonyOS/Day3 Assingment/trainingApp/entry/src/main/config.json b/HarmonyOS/Day3 Assingment/trainingApp/entry/src/main/config.json new file mode 100644 index 00000000..83cb73f6 --- /dev/null +++ b/HarmonyOS/Day3 Assingment/trainingApp/entry/src/main/config.json @@ -0,0 +1,58 @@ +{ + "app": { + "bundleName": "com.example.trainingapp", + "vendor": "example", + "version": { + "code": 1000000, + "name": "1.0.0" + }, + "apiVersion": { + "compatible": 5, + "target": 5, + "releaseType": "Release" + } + }, + "deviceConfig": {}, + "module": { + "package": "com.example.trainingapp", + "name": ".MyApplication", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry", + "moduleType": "entry" + }, + "abilities": [ + { + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "orientation": "unspecified", + "name": "com.example.trainingapp.MainAbility", + "icon": "$media:icon", + "description": "$string:mainability_description", + "label": "$string:app_name", + "type": "page", + "launchType": "standard" + }, + { + "permissions": [ + "com.example.trainingapp.DataAbilityShellProvider.PROVIDER" + ], + "name": "com.example.trainingapp.PersonDataAbility", + "icon": "$media:icon", + "type": "data", + "uri": "dataability://com.example.trainingapp.PersonDataAbility" + } + ] + } +} \ No newline at end of file diff --git a/HarmonyOS/Day3 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/DbUtils.java b/HarmonyOS/Day3 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/DbUtils.java new file mode 100644 index 00000000..89aac61c --- /dev/null +++ b/HarmonyOS/Day3 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/DbUtils.java @@ -0,0 +1,91 @@ +package com.example.trainingapp; + +import ohos.aafwk.ability.DataAbilityHelper; +import ohos.aafwk.ability.DataAbilityRemoteException; +import ohos.app.Context; +import ohos.data.dataability.DataAbilityPredicates; +import ohos.data.rdb.ValuesBucket; +import ohos.data.resultset.ResultSet; +import ohos.hiviewdfx.HiLog; +import ohos.hiviewdfx.HiLogLabel; +import ohos.utils.net.Uri; + +public class DbUtils { + private static final HiLogLabel LABEL_LOG = new HiLogLabel(3, 0xD001100, "DbUtils"); + + public static final String BASE_URI = "dataability:///com.example.trainingapp.PersonDataAbility"; + + public static final String DATA_PATH = "/person"; + + public static final String DB_COLUMN_PERSON_ID = "id"; + + public static final String DB_COLUMN_FIRSTNAME = "first_name"; + + public static final String DB_COLUMN_LASTNAME = "last_name"; + + public static final String DB_COLUMN_GENDER = "gender"; + + public static final String DB_COLUMN_EMAIL = "email"; + + public static final String DB_COLUMN_PASSWORD = "password"; + + public static final String DB_COLUMN_PHONE = "phone"; + + public static ResultSet query(Context context, DataAbilityPredicates predicates) { + DataAbilityHelper databaseHelper = DataAbilityHelper.creator(context); + + String[] columns = new String[] {DB_COLUMN_PERSON_ID, + DB_COLUMN_FIRSTNAME, DB_COLUMN_LASTNAME, DB_COLUMN_GENDER, DB_COLUMN_EMAIL, DB_COLUMN_PHONE, DB_COLUMN_PASSWORD}; + + ResultSet resultSet = null; + + try { + resultSet = databaseHelper.query(Uri.parse(BASE_URI + DATA_PATH), + columns, predicates); + } catch (IllegalStateException | DataAbilityRemoteException exception) { + HiLog.error(LABEL_LOG, "query: dataRemote exception | illegalStateException"); + } + return resultSet; + } + + public static void showDB(Context context) { + ResultSet resultSet = DbUtils.query(context, null); + if(resultSet == null) { + HiLog.error(LABEL_LOG, "resultset empty"); + return; + } + if(resultSet.getRowCount()==0) { + HiLog.error(LABEL_LOG, "row count 0"); + return; + } + + resultSet.goToFirstRow(); + do { + int id = resultSet.getInt(resultSet.getColumnIndexForName(DbUtils.DB_COLUMN_PERSON_ID)); + String name = resultSet.getString(resultSet.getColumnIndexForName(DbUtils.DB_COLUMN_FIRSTNAME)); + String email = resultSet.getString(resultSet.getColumnIndexForName(DbUtils.DB_COLUMN_EMAIL)); + String gender = resultSet.getString(resultSet.getColumnIndexForName(DbUtils.DB_COLUMN_GENDER)); + String password = resultSet.getString(resultSet.getColumnIndexForName(DbUtils.DB_COLUMN_PASSWORD)); + HiLog.info(LABEL_LOG, "query: Id :" + id + " Name :" + name + " Gender :" + gender + " Email :" + email + " Password :" + password); + } while (resultSet.goToNextRow()); + } + + public static void insert(Context context, String firstname, String lastname, String gender, String email, String phone, String password) { + DataAbilityHelper databaseHelper = DataAbilityHelper.creator(context); + + ValuesBucket valuesBucket = new ValuesBucket(); + valuesBucket.putString(DB_COLUMN_FIRSTNAME, firstname); + valuesBucket.putString(DB_COLUMN_LASTNAME, lastname); + valuesBucket.putString(DB_COLUMN_GENDER, gender); + valuesBucket.putString(DB_COLUMN_EMAIL, email); + valuesBucket.putString(DB_COLUMN_PHONE, phone); + valuesBucket.putString(DB_COLUMN_PASSWORD, password); + try { + if (databaseHelper.insert(Uri.parse(BASE_URI + DATA_PATH), valuesBucket) != -1) { + HiLog.info(LABEL_LOG, "insert successful"); + } + } catch (DataAbilityRemoteException | IllegalStateException exception) { + HiLog.error(LABEL_LOG, "insert: dataRemote exception|illegalStateException"); + } + } +} diff --git a/HarmonyOS/Day3 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/MainAbility.java b/HarmonyOS/Day3 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/MainAbility.java new file mode 100644 index 00000000..bf407ed6 --- /dev/null +++ b/HarmonyOS/Day3 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/MainAbility.java @@ -0,0 +1,13 @@ +package com.example.trainingapp; + +import com.example.trainingapp.slice.MainAbilitySlice; +import ohos.aafwk.ability.Ability; +import ohos.aafwk.content.Intent; + +public class MainAbility extends Ability { + @Override + public void onStart(Intent intent) { + super.onStart(intent); + super.setMainRoute(MainAbilitySlice.class.getName()); + } +} diff --git a/HarmonyOS/Day3 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/MyApplication.java b/HarmonyOS/Day3 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/MyApplication.java new file mode 100644 index 00000000..ecf61daa --- /dev/null +++ b/HarmonyOS/Day3 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/MyApplication.java @@ -0,0 +1,10 @@ +package com.example.trainingapp; + +import ohos.aafwk.ability.AbilityPackage; + +public class MyApplication extends AbilityPackage { + @Override + public void onInitialize() { + super.onInitialize(); + } +} diff --git a/HarmonyOS/Day3 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/PersonDataAbility.java b/HarmonyOS/Day3 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/PersonDataAbility.java new file mode 100644 index 00000000..236bcf77 --- /dev/null +++ b/HarmonyOS/Day3 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/PersonDataAbility.java @@ -0,0 +1,134 @@ +package com.example.trainingapp; + +import ohos.aafwk.ability.Ability; +import ohos.aafwk.ability.DataAbilityHelper; +import ohos.aafwk.content.Intent; +import ohos.data.DatabaseHelper; +import ohos.data.dataability.DataAbilityUtils; +import ohos.data.rdb.*; +import ohos.data.resultset.ResultSet; +import ohos.data.dataability.DataAbilityPredicates; +import ohos.hiviewdfx.HiLog; +import ohos.hiviewdfx.HiLogLabel; +import ohos.utils.net.Uri; +import ohos.utils.PacMap; + +import java.io.FileDescriptor; + +public class PersonDataAbility extends Ability { + private static final HiLogLabel LABEL_LOG = new HiLogLabel(3, 0xD001100, "PersonDataAbility"); + + private static final String DB_NAME = "persondataability.db"; + + private static final String DB_TAB_NAME = "person"; + + private static final String DB_COLUMN_PERSON_ID = "id"; + + private static final String DB_COLUMN_FIRSTNAME = "first_name"; + + private static final String DB_COLUMN_LASTNAME = "last_name"; + + private static final String DB_COLUMN_GENDER = "gender"; + + private static final String DB_COLUMN_EMAIL = "email"; + + private static final String DB_COLUMN_PASSWORD = "password"; + + private static final String DB_COLUMN_PHONE = "phone"; + + private static final int DB_VERSION = 1; + + private final StoreConfig config = StoreConfig.newDefaultConfig(DB_NAME); + + private RdbStore rdbStore; + + private final RdbOpenCallback rdbOpenCallback = new RdbOpenCallback() { + @Override + public void onCreate(RdbStore store) { + store.executeSql("create table if not exists " + + DB_TAB_NAME + " (" + + DB_COLUMN_PERSON_ID + " integer primary key autoincrement, " + + DB_COLUMN_FIRSTNAME + " text not null, " + + DB_COLUMN_LASTNAME + " text not null, " + + DB_COLUMN_GENDER + " text not null, " + + DB_COLUMN_EMAIL + " text not null, " + + DB_COLUMN_PHONE + " text not null, " + + DB_COLUMN_PASSWORD + " text not null)"); + } + + @Override + public void onUpgrade(RdbStore store, int oldVersion, int newVersion) { + } + }; + + @Override + public void onStart(Intent intent) { + super.onStart(intent); + HiLog.info(LABEL_LOG, "PersonDataAbility onStart"); + + DatabaseHelper databaseHelper = new DatabaseHelper(this); + rdbStore = databaseHelper.getRdbStore(config, DB_VERSION, rdbOpenCallback, null); + } + + @Override + public ResultSet query(Uri uri, String[] columns, DataAbilityPredicates predicates) { + RdbPredicates rdbPredicates = DataAbilityUtils.createRdbPredicates(predicates, DB_TAB_NAME); + ResultSet resultSet = rdbStore.query(rdbPredicates, columns); + if (resultSet == null) { + HiLog.info(LABEL_LOG, "resultSet is null"); + } + return resultSet; + } + + @Override + public int insert(Uri uri, ValuesBucket value) { + HiLog.info(LABEL_LOG, "PersonDataAbility insert"); + String path = uri.getLastPath(); + if (!"person".equals(path)) { + HiLog.info(LABEL_LOG, "DataAbility insert path is not matched"); + return -1; + } + ValuesBucket values = new ValuesBucket(); + values.putInteger(DB_COLUMN_PERSON_ID, value.getInteger(DB_COLUMN_PERSON_ID)); + values.putString(DB_COLUMN_FIRSTNAME, value.getString(DB_COLUMN_FIRSTNAME)); + values.putString(DB_COLUMN_LASTNAME, value.getString(DB_COLUMN_LASTNAME)); + values.putString(DB_COLUMN_GENDER, value.getString(DB_COLUMN_GENDER)); + values.putString(DB_COLUMN_EMAIL, value.getString(DB_COLUMN_EMAIL)); + values.putString(DB_COLUMN_PHONE, value.getString(DB_COLUMN_PHONE)); + values.putString(DB_COLUMN_PASSWORD, value.getString(DB_COLUMN_PASSWORD)); + + int index = (int) rdbStore.insert(DB_TAB_NAME, values); + DataAbilityHelper.creator(this, uri).notifyChange(uri); + return index; + } + + @Override + public int delete(Uri uri, DataAbilityPredicates predicates) { + return 0; + } + + @Override + public int update(Uri uri, ValuesBucket value, DataAbilityPredicates predicates) { + return 0; + } + + @Override + public FileDescriptor openFile(Uri uri, String mode) { + return null; + } + + @Override + public String[] getFileTypes(Uri uri, String mimeTypeFilter) { + return new String[0]; + } + + @Override + public PacMap call(String method, String arg, PacMap extras) { + return null; + } + + @Override + public String getType(Uri uri) { + return null; + } +} diff --git a/HarmonyOS/Day3 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/slice/LoginSlice.java b/HarmonyOS/Day3 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/slice/LoginSlice.java new file mode 100644 index 00000000..c28f12a7 --- /dev/null +++ b/HarmonyOS/Day3 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/slice/LoginSlice.java @@ -0,0 +1,63 @@ +package com.example.trainingapp.slice; + +import ohos.aafwk.ability.AbilitySlice; +import ohos.aafwk.content.Intent; +import com.example.trainingapp.ResourceTable; +import ohos.agp.components.Button; +import ohos.agp.components.Component; +import ohos.agp.components.Text; +import ohos.agp.components.TextField; +import ohos.hiviewdfx.HiLog; +import ohos.hiviewdfx.HiLogLabel; +import ohos.data.dataability.DataAbilityPredicates; +import com.example.trainingapp.DbUtils; +import ohos.data.resultset.ResultSet; + +public class LoginSlice extends AbilitySlice { + private static final HiLogLabel LABEL_LOG = new HiLogLabel(3, 0xD001100, "LoginSlice"); + + TextField email, password; + Text loginError; + Button loginBtn; + @Override + protected void onStart(Intent intent){ + super.onStart(intent); + super.setUIContent(ResourceTable.Layout_login); + + email = (TextField) findComponentById(ResourceTable.Id_emailLogin); + password = (TextField) findComponentById(ResourceTable.Id_passwordLogin); + loginError = (Text) findComponentById(ResourceTable.Id_loginError); + loginBtn = (Button) findComponentById(ResourceTable.Id_loginButton); + + loginBtn.setClickedListener(new Component.ClickedListener() { + @Override + public void onClick(Component component) { + validateUser(); + } + }); + } + + private void validateUser() { + loginError.setText(null); + DataAbilityPredicates predicates = new DataAbilityPredicates(); + predicates.equalTo(DbUtils.DB_COLUMN_EMAIL, email.getText()); + predicates.equalTo(DbUtils.DB_COLUMN_PASSWORD, password.getText()); + + ResultSet resultSet = DbUtils.query(this, predicates); + if(resultSet == null || resultSet.getRowCount()==0) { + HiLog.error(LABEL_LOG, "resultset empty || getrowcount = 0"); + loginError.setVisibility(Component.VISIBLE); + return; + } + + resultSet.goToFirstRow(); + int id = resultSet.getInt(resultSet.getColumnIndexForName(DbUtils.DB_COLUMN_PERSON_ID)); + String name = resultSet.getString(resultSet.getColumnIndexForName(DbUtils.DB_COLUMN_FIRSTNAME)); + String email = resultSet.getString(resultSet.getColumnIndexForName(DbUtils.DB_COLUMN_EMAIL)); + String gender = resultSet.getString(resultSet.getColumnIndexForName(DbUtils.DB_COLUMN_GENDER)); + HiLog.info(LABEL_LOG, "query: Id :" + id + " Name :" + name + " Gender :" + gender + " Email :" + email); + + present(new LoginSuccessSlice(), new Intent()); + + } +} diff --git a/HarmonyOS/Day3 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/slice/LoginSuccessSlice.java b/HarmonyOS/Day3 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/slice/LoginSuccessSlice.java new file mode 100644 index 00000000..c50ce89e --- /dev/null +++ b/HarmonyOS/Day3 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/slice/LoginSuccessSlice.java @@ -0,0 +1,13 @@ +package com.example.trainingapp.slice; + +import ohos.aafwk.ability.AbilitySlice; +import ohos.aafwk.content.Intent; +import com.example.trainingapp.ResourceTable; + +public class LoginSuccessSlice extends AbilitySlice { + @Override + protected void onStart(Intent intent){ + super.onStart(intent); + super.setUIContent(ResourceTable.Layout_login_success); + } +} diff --git a/HarmonyOS/Day3 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/slice/MainAbilitySlice.java b/HarmonyOS/Day3 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/slice/MainAbilitySlice.java new file mode 100644 index 00000000..2a8fbb41 --- /dev/null +++ b/HarmonyOS/Day3 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/slice/MainAbilitySlice.java @@ -0,0 +1,30 @@ +package com.example.trainingapp.slice; + +import com.example.trainingapp.ResourceTable; +import ohos.aafwk.ability.AbilitySlice; +import ohos.aafwk.content.Intent; +import ohos.agp.components.Button; + +public class MainAbilitySlice extends AbilitySlice { + @Override + public void onStart(Intent intent) { + super.onStart(intent); + super.setUIContent(ResourceTable.Layout_ability_main); + + Button bt1 = (Button) findComponentById(ResourceTable.Id_log); + Button bt2 = (Button) findComponentById(ResourceTable.Id_sign); + + bt1.setClickedListener(listener -> present(new LoginSlice(), new Intent())); + bt2.setClickedListener(listener -> present(new SignupSlice(), new Intent())); + } + + @Override + public void onActive() { + super.onActive(); + } + + @Override + public void onForeground(Intent intent) { + super.onForeground(intent); + } +} diff --git a/HarmonyOS/Day3 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/slice/SignupSlice.java b/HarmonyOS/Day3 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/slice/SignupSlice.java new file mode 100644 index 00000000..118d856f --- /dev/null +++ b/HarmonyOS/Day3 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/slice/SignupSlice.java @@ -0,0 +1,136 @@ +package com.example.trainingapp.slice; + +import ohos.aafwk.ability.AbilitySlice; +import com.example.trainingapp.DbUtils; +import ohos.aafwk.content.Intent; +import com.example.trainingapp.ResourceTable; +import ohos.agp.components.*; +import java.util.regex.Pattern; +import ohos.hiviewdfx.HiLog; +import ohos.hiviewdfx.HiLogLabel; + +public class SignupSlice extends AbilitySlice { + private static final HiLogLabel LABEL_LOG = new HiLogLabel(3, 0xD001100, "SignupSlice"); + TextField firstName, lastName, email, password, mobile; + Text firstError, lastError, emailError, passError, mobileError, radioError; + RadioButton maleRadio,femaleRadio; + Button signupBtn; + @Override + protected void onStart(Intent intent){ + super.onStart(intent); + super.setUIContent(ResourceTable.Layout_signup); + + + firstName = (TextField) findComponentById(ResourceTable.Id_first_name); + lastName = (TextField) findComponentById((ResourceTable.Id_last_name)); + email = (TextField) findComponentById(ResourceTable.Id_email); + password = (TextField) findComponentById(ResourceTable.Id_password); + mobile = (TextField) findComponentById(ResourceTable.Id_phone); + + maleRadio = (RadioButton) findComponentById(ResourceTable.Id_male); + femaleRadio = (RadioButton) findComponentById(ResourceTable.Id_female); + + firstError = (Text) findComponentById(ResourceTable.Id_firstError); + lastError = (Text) findComponentById(ResourceTable.Id_lastError); + emailError = (Text) findComponentById(ResourceTable.Id_emailError); + passError = (Text) findComponentById(ResourceTable.Id_passwordError); + mobileError = (Text) findComponentById(ResourceTable.Id_phoneError); + radioError = (Text) findComponentById(ResourceTable.Id_radioError); + + signupBtn =(Button) findComponentById(ResourceTable.Id_signup); + + signupBtn.setClickedListener(new Component.ClickedListener() { + @Override + public void onClick(Component component) { + if(checkValidity() == true){ + String gender; + if(maleRadio.isChecked()) gender = "Male"; + else gender = "Female"; + DbUtils.insert(SignupSlice.this, firstName.getText(), lastName.getText(), gender, email.getText(), mobile.getText(), password.getText()); + HiLog.info(LABEL_LOG, "User registered"); + DbUtils.showDB(SignupSlice.this); + + present(new SignupSuccessSlice(), new Intent()); + } + } + }); + + } + public boolean isNameValid(TextField name){ + String str = name.getText(); + String regex = "[a-zA-Z]+"; + Pattern p = Pattern.compile(regex); + + return p.matcher(str).matches(); + } + + public boolean isEmailValid(TextField email){ + String str = email.getText(); + String regex = ".+@.+\\..+"; + Pattern p = Pattern.compile(regex); + + return p.matcher(str).matches(); + } + + public boolean isPhoneValid(TextField mobile){ + String str = mobile.getText(); + String regex = "[1-9][0-9]{9}"; + Pattern p = Pattern.compile(regex); + + return p.matcher(str).matches(); + } + + public boolean isPassValid(TextField password){ + String str = password.getText(); + String regex = ".{5,}"; + Pattern p = Pattern.compile(regex); + return p.matcher(str).matches(); + } + + public boolean checkValidity(){ + boolean b = true; + if(firstName.getText() == null || firstName.getText().isEmpty() || !isNameValid(firstName)){ + firstError.setVisibility(Component.VISIBLE); + b = false; + } + else{ + firstError.setVisibility(Component.INVISIBLE); + } + if(lastName.getText() == null || lastName.getText().isEmpty() || !isNameValid(lastName)){ + lastError.setVisibility(Component.VISIBLE); + b = false; + } + else{ + lastError.setVisibility(Component.INVISIBLE); + } + if(email.getText() == null || email.getText().isEmpty() || !isEmailValid(email)){ + emailError.setVisibility(Component.VISIBLE); + b = false; + } + else{ + emailError.setVisibility(Component.INVISIBLE); + } + if(mobile.getText() == null || mobile.getText().isEmpty() || !isPhoneValid(mobile)){ + mobileError.setVisibility(Component.VISIBLE); + b = false; + } + else{ + mobileError.setVisibility(Component.INVISIBLE); + } + if(password.getText() == null || password.getText().isEmpty() || !isPassValid(password)){ + passError.setVisibility(Component.VISIBLE); + b = false; + } + else{ + passError.setVisibility(Component.INVISIBLE); + } + if(!maleRadio.isChecked() && !femaleRadio.isChecked()){ + radioError.setVisibility(Component.VISIBLE); + b = false; + } + else{ + radioError.setVisibility(Component.INVISIBLE); + } + return b; + } +} diff --git a/HarmonyOS/Day3 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/slice/SignupSuccessSlice.java b/HarmonyOS/Day3 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/slice/SignupSuccessSlice.java new file mode 100644 index 00000000..93414cbe --- /dev/null +++ b/HarmonyOS/Day3 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/slice/SignupSuccessSlice.java @@ -0,0 +1,13 @@ +package com.example.trainingapp.slice; + +import ohos.aafwk.ability.AbilitySlice; +import ohos.aafwk.content.Intent; +import com.example.trainingapp.ResourceTable; + +public class SignupSuccessSlice extends AbilitySlice { + @Override + protected void onStart(Intent intent){ + super.onStart(intent); + super.setUIContent(ResourceTable.Layout_signup_success); + } +} diff --git a/HarmonyOS/Day3 Assingment/trainingApp/entry/src/main/resources/base/element/string.json b/HarmonyOS/Day3 Assingment/trainingApp/entry/src/main/resources/base/element/string.json new file mode 100644 index 00000000..fb02a338 --- /dev/null +++ b/HarmonyOS/Day3 Assingment/trainingApp/entry/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "app_name", + "value": "trainingApp" + }, + { + "name": "mainability_description", + "value": "Java_Phone_Empty Feature Ability" + }, + { + "name": "mainability_HelloWorld", + "value": "Hello World" + } + ] +} \ No newline at end of file diff --git a/HarmonyOS/Day3 Assingment/trainingApp/entry/src/main/resources/base/graphic/background_ability_main.xml b/HarmonyOS/Day3 Assingment/trainingApp/entry/src/main/resources/base/graphic/background_ability_main.xml new file mode 100644 index 00000000..c0c0a3df --- /dev/null +++ b/HarmonyOS/Day3 Assingment/trainingApp/entry/src/main/resources/base/graphic/background_ability_main.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/HarmonyOS/Day3 Assingment/trainingApp/entry/src/main/resources/base/layout/ability_main.xml b/HarmonyOS/Day3 Assingment/trainingApp/entry/src/main/resources/base/layout/ability_main.xml new file mode 100644 index 00000000..9440f26f --- /dev/null +++ b/HarmonyOS/Day3 Assingment/trainingApp/entry/src/main/resources/base/layout/ability_main.xml @@ -0,0 +1,51 @@ + + + + + + + + \ No newline at end of file diff --git a/HarmonyOS/Day3 Assingment/trainingApp/entry/src/main/resources/base/layout/login.xml b/HarmonyOS/Day3 Assingment/trainingApp/entry/src/main/resources/base/layout/login.xml new file mode 100644 index 00000000..f9fe34fb --- /dev/null +++ b/HarmonyOS/Day3 Assingment/trainingApp/entry/src/main/resources/base/layout/login.xml @@ -0,0 +1,73 @@ + + + + + + + + + + \ No newline at end of file diff --git a/HarmonyOS/Day3 Assingment/trainingApp/entry/src/main/resources/base/layout/login_success.xml b/HarmonyOS/Day3 Assingment/trainingApp/entry/src/main/resources/base/layout/login_success.xml new file mode 100644 index 00000000..11d27d8a --- /dev/null +++ b/HarmonyOS/Day3 Assingment/trainingApp/entry/src/main/resources/base/layout/login_success.xml @@ -0,0 +1,14 @@ + + + + + \ No newline at end of file diff --git a/HarmonyOS/Day3 Assingment/trainingApp/entry/src/main/resources/base/layout/signup.xml b/HarmonyOS/Day3 Assingment/trainingApp/entry/src/main/resources/base/layout/signup.xml new file mode 100644 index 00000000..9b0527a0 --- /dev/null +++ b/HarmonyOS/Day3 Assingment/trainingApp/entry/src/main/resources/base/layout/signup.xml @@ -0,0 +1,190 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/HarmonyOS/Day3 Assingment/trainingApp/entry/src/main/resources/base/layout/signup_success.xml b/HarmonyOS/Day3 Assingment/trainingApp/entry/src/main/resources/base/layout/signup_success.xml new file mode 100644 index 00000000..a362048b --- /dev/null +++ b/HarmonyOS/Day3 Assingment/trainingApp/entry/src/main/resources/base/layout/signup_success.xml @@ -0,0 +1,15 @@ + + + + + + \ No newline at end of file diff --git a/HarmonyOS/Day3 Assingment/trainingApp/entry/src/main/resources/base/media/icon.png b/HarmonyOS/Day3 Assingment/trainingApp/entry/src/main/resources/base/media/icon.png new file mode 100644 index 00000000..ce307a88 Binary files /dev/null and b/HarmonyOS/Day3 Assingment/trainingApp/entry/src/main/resources/base/media/icon.png differ diff --git a/HarmonyOS/Day3 Assingment/trainingApp/entry/src/ohosTest/config.json b/HarmonyOS/Day3 Assingment/trainingApp/entry/src/ohosTest/config.json new file mode 100644 index 00000000..0e29531e --- /dev/null +++ b/HarmonyOS/Day3 Assingment/trainingApp/entry/src/ohosTest/config.json @@ -0,0 +1,41 @@ +{ + "app": { + "bundleName": "com.example.trainingapp", + "vendor": "example", + "version": { + "code": 1000000, + "name": "1.0.0" + }, + "apiVersion": { + "compatible": 5, + "target": 5, + "releaseType": "Release" + } + }, + "deviceConfig": {}, + "module": { + "package": "com.example.trainingapp", + "name": "testModule", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry_test", + "moduleType": "feature", + "installationFree": true + }, + "abilities": [ + { + "name": "decc.testkit.runner.EntryAbility", + "description": "Test Entry Ability", + "icon": "$media:icon", + "label": "$string:app_name", + "launchType": "standard", + "orientation": "landscape", + "visible": true, + "type": "page" + } + ] + } +} \ No newline at end of file diff --git a/HarmonyOS/Day3 Assingment/trainingApp/entry/src/ohosTest/java/com/example/trainingapp/ExampleOhosTest.java b/HarmonyOS/Day3 Assingment/trainingApp/entry/src/ohosTest/java/com/example/trainingapp/ExampleOhosTest.java new file mode 100644 index 00000000..3340a0d6 --- /dev/null +++ b/HarmonyOS/Day3 Assingment/trainingApp/entry/src/ohosTest/java/com/example/trainingapp/ExampleOhosTest.java @@ -0,0 +1,14 @@ +package com.example.trainingapp; + +import ohos.aafwk.ability.delegation.AbilityDelegatorRegistry; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class ExampleOhosTest { + @Test + public void testBundleName() { + final String actualBundleName = AbilityDelegatorRegistry.getArguments().getTestBundleName(); + assertEquals("com.example.trainingapp", actualBundleName); + } +} \ No newline at end of file diff --git a/HarmonyOS/Day3 Assingment/trainingApp/entry/src/test/java/com/example/trainingapp/ExampleTest.java b/HarmonyOS/Day3 Assingment/trainingApp/entry/src/test/java/com/example/trainingapp/ExampleTest.java new file mode 100644 index 00000000..b047cceb --- /dev/null +++ b/HarmonyOS/Day3 Assingment/trainingApp/entry/src/test/java/com/example/trainingapp/ExampleTest.java @@ -0,0 +1,9 @@ +package com.example.trainingapp; + +import org.junit.Test; + +public class ExampleTest { + @Test + public void onStart() { + } +} diff --git a/HarmonyOS/Day3 Assingment/trainingApp/gradle.properties b/HarmonyOS/Day3 Assingment/trainingApp/gradle.properties new file mode 100644 index 00000000..0daf1830 --- /dev/null +++ b/HarmonyOS/Day3 Assingment/trainingApp/gradle.properties @@ -0,0 +1,10 @@ +# Project-wide Gradle settings. +# IDE (e.g. DevEco Studio) users: +# Gradle settings configured through the IDE *will override* +# any settings specified in this file. +# For more details on how to configure your build environment visit +# http://www.gradle.org/docs/current/userguide/build_environment.html +# Specifies the JVM arguments used for the daemon process. +# The setting is particularly useful for tweaking memory settings. +# If the Chinese output is garbled, please configure the following parameter. +# org.gradle.jvmargs=-Dfile.encoding=GBK diff --git a/HarmonyOS/Day3 Assingment/trainingApp/gradle/wrapper/gradle-wrapper.jar b/HarmonyOS/Day3 Assingment/trainingApp/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 00000000..490fda85 Binary files /dev/null and b/HarmonyOS/Day3 Assingment/trainingApp/gradle/wrapper/gradle-wrapper.jar differ diff --git a/HarmonyOS/Day3 Assingment/trainingApp/gradle/wrapper/gradle-wrapper.properties b/HarmonyOS/Day3 Assingment/trainingApp/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 00000000..f59159e8 --- /dev/null +++ b/HarmonyOS/Day3 Assingment/trainingApp/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://repo.huaweicloud.com/gradle/gradle-6.3-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/HarmonyOS/Day3 Assingment/trainingApp/gradlew b/HarmonyOS/Day3 Assingment/trainingApp/gradlew new file mode 100644 index 00000000..2fe81a7d --- /dev/null +++ b/HarmonyOS/Day3 Assingment/trainingApp/gradlew @@ -0,0 +1,183 @@ +#!/usr/bin/env sh + +# +# Copyright 2015 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin or MSYS, switch paths to Windows format before running java +if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=`expr $i + 1` + done + case $i in + 0) set -- ;; + 1) set -- "$args0" ;; + 2) set -- "$args0" "$args1" ;; + 3) set -- "$args0" "$args1" "$args2" ;; + 4) set -- "$args0" "$args1" "$args2" "$args3" ;; + 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=`save "$@"` + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +exec "$JAVACMD" "$@" diff --git a/HarmonyOS/Day3 Assingment/trainingApp/gradlew.bat b/HarmonyOS/Day3 Assingment/trainingApp/gradlew.bat new file mode 100644 index 00000000..62bd9b9c --- /dev/null +++ b/HarmonyOS/Day3 Assingment/trainingApp/gradlew.bat @@ -0,0 +1,103 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windows variants + +if not "%OS%" == "Windows_NT" goto win9xME_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/HarmonyOS/Day3 Assingment/trainingApp/settings.gradle b/HarmonyOS/Day3 Assingment/trainingApp/settings.gradle new file mode 100644 index 00000000..4773db73 --- /dev/null +++ b/HarmonyOS/Day3 Assingment/trainingApp/settings.gradle @@ -0,0 +1 @@ +include ':entry' diff --git a/HarmonyOS/Day4 Assingment/trainingApp/.gitignore b/HarmonyOS/Day4 Assingment/trainingApp/.gitignore new file mode 100644 index 00000000..37a4eb8b --- /dev/null +++ b/HarmonyOS/Day4 Assingment/trainingApp/.gitignore @@ -0,0 +1,15 @@ +*.iml +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store +/build +/captures +.externalNativeBuild +/entry/.preview +.cxx diff --git a/HarmonyOS/Day4 Assingment/trainingApp/.idea/.gitignore b/HarmonyOS/Day4 Assingment/trainingApp/.idea/.gitignore new file mode 100644 index 00000000..26d33521 --- /dev/null +++ b/HarmonyOS/Day4 Assingment/trainingApp/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/HarmonyOS/Day4 Assingment/trainingApp/.idea/compiler.xml b/HarmonyOS/Day4 Assingment/trainingApp/.idea/compiler.xml new file mode 100644 index 00000000..61a9130c --- /dev/null +++ b/HarmonyOS/Day4 Assingment/trainingApp/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/HarmonyOS/Day4 Assingment/trainingApp/.idea/gradle.xml b/HarmonyOS/Day4 Assingment/trainingApp/.idea/gradle.xml new file mode 100644 index 00000000..b9090f42 --- /dev/null +++ b/HarmonyOS/Day4 Assingment/trainingApp/.idea/gradle.xml @@ -0,0 +1,22 @@ + + + + + + + \ No newline at end of file diff --git a/HarmonyOS/Day4 Assingment/trainingApp/.idea/jarRepositories.xml b/HarmonyOS/Day4 Assingment/trainingApp/.idea/jarRepositories.xml new file mode 100644 index 00000000..1dfcd020 --- /dev/null +++ b/HarmonyOS/Day4 Assingment/trainingApp/.idea/jarRepositories.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/HarmonyOS/Day4 Assingment/trainingApp/.idea/misc.xml b/HarmonyOS/Day4 Assingment/trainingApp/.idea/misc.xml new file mode 100644 index 00000000..58918f50 --- /dev/null +++ b/HarmonyOS/Day4 Assingment/trainingApp/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/HarmonyOS/Day4 Assingment/trainingApp/.idea/previewer/phone/phoneSettingConfig_1825807532.json b/HarmonyOS/Day4 Assingment/trainingApp/.idea/previewer/phone/phoneSettingConfig_1825807532.json new file mode 100644 index 00000000..f505e6b9 --- /dev/null +++ b/HarmonyOS/Day4 Assingment/trainingApp/.idea/previewer/phone/phoneSettingConfig_1825807532.json @@ -0,0 +1,25 @@ +{ + "setting": { + "1.0.1": { + "Language": { + "args": { + "Language": "zh-CN" + } + } + } + }, + "frontend": { + "1.0.0": { + "Resolution": { + "args": { + "Resolution": "360*780" + } + }, + "DeviceType": { + "args": { + "DeviceType": "phone" + } + } + } + } +} \ No newline at end of file diff --git a/HarmonyOS/Day4 Assingment/trainingApp/.idea/previewer/previewConfig.json b/HarmonyOS/Day4 Assingment/trainingApp/.idea/previewer/previewConfig.json new file mode 100644 index 00000000..0c811855 --- /dev/null +++ b/HarmonyOS/Day4 Assingment/trainingApp/.idea/previewer/previewConfig.json @@ -0,0 +1,9 @@ +{ + "1.0.0": { + "LastPreviewDevice": { + "C:\\Users\\jjati\\DevEcoStudioProjects\\trainingApp\\entry": [ + "phone" + ] + } + } +} \ No newline at end of file diff --git a/HarmonyOS/Day4 Assingment/trainingApp/build.gradle b/HarmonyOS/Day4 Assingment/trainingApp/build.gradle new file mode 100644 index 00000000..1dc510ff --- /dev/null +++ b/HarmonyOS/Day4 Assingment/trainingApp/build.gradle @@ -0,0 +1,37 @@ +// Top-level build file where you can add configuration options common to all sub-projects/modules. +apply plugin: 'com.huawei.ohos.app' + +ohos { + compileSdkVersion 5 + defaultConfig { + compatibleSdkVersion 5 + } +} + +buildscript { + repositories { + maven { + url 'https://repo.huaweicloud.com/repository/maven/' + } + maven { + url 'https://developer.huawei.com/repo/' + } + jcenter() + } + dependencies { + classpath 'com.huawei.ohos:hap:2.4.2.7' + classpath 'com.huawei.ohos:decctest:1.0.0.7' + } +} + +allprojects { + repositories { + maven { + url 'https://repo.huaweicloud.com/repository/maven/' + } + maven { + url 'https://developer.huawei.com/repo/' + } + jcenter() + } +} diff --git a/HarmonyOS/Day4 Assingment/trainingApp/entry/.gitignore b/HarmonyOS/Day4 Assingment/trainingApp/entry/.gitignore new file mode 100644 index 00000000..796b96d1 --- /dev/null +++ b/HarmonyOS/Day4 Assingment/trainingApp/entry/.gitignore @@ -0,0 +1 @@ +/build diff --git a/HarmonyOS/Day4 Assingment/trainingApp/entry/build.gradle b/HarmonyOS/Day4 Assingment/trainingApp/entry/build.gradle new file mode 100644 index 00000000..752a0370 --- /dev/null +++ b/HarmonyOS/Day4 Assingment/trainingApp/entry/build.gradle @@ -0,0 +1,26 @@ +apply plugin: 'com.huawei.ohos.hap' +apply plugin: 'com.huawei.ohos.decctest' +ohos { + compileSdkVersion 5 + defaultConfig { + compatibleSdkVersion 5 + } + buildTypes { + release { + proguardOpt { + proguardEnabled false + rulesFiles 'proguard-rules.pro' + } + } + } + +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar', '*.har']) + testImplementation 'junit:junit:4.13' + ohosTestImplementation 'com.huawei.ohos.testkit:runner:1.0.0.100' +} +decc { + supportType = ['html','xml'] +} diff --git a/HarmonyOS/Day4 Assingment/trainingApp/entry/proguard-rules.pro b/HarmonyOS/Day4 Assingment/trainingApp/entry/proguard-rules.pro new file mode 100644 index 00000000..f7666e47 --- /dev/null +++ b/HarmonyOS/Day4 Assingment/trainingApp/entry/proguard-rules.pro @@ -0,0 +1 @@ +# config module specific ProGuard rules here. \ No newline at end of file diff --git a/HarmonyOS/Day4 Assingment/trainingApp/entry/src/main/config.json b/HarmonyOS/Day4 Assingment/trainingApp/entry/src/main/config.json new file mode 100644 index 00000000..83cb73f6 --- /dev/null +++ b/HarmonyOS/Day4 Assingment/trainingApp/entry/src/main/config.json @@ -0,0 +1,58 @@ +{ + "app": { + "bundleName": "com.example.trainingapp", + "vendor": "example", + "version": { + "code": 1000000, + "name": "1.0.0" + }, + "apiVersion": { + "compatible": 5, + "target": 5, + "releaseType": "Release" + } + }, + "deviceConfig": {}, + "module": { + "package": "com.example.trainingapp", + "name": ".MyApplication", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry", + "moduleType": "entry" + }, + "abilities": [ + { + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "orientation": "unspecified", + "name": "com.example.trainingapp.MainAbility", + "icon": "$media:icon", + "description": "$string:mainability_description", + "label": "$string:app_name", + "type": "page", + "launchType": "standard" + }, + { + "permissions": [ + "com.example.trainingapp.DataAbilityShellProvider.PROVIDER" + ], + "name": "com.example.trainingapp.PersonDataAbility", + "icon": "$media:icon", + "type": "data", + "uri": "dataability://com.example.trainingapp.PersonDataAbility" + } + ] + } +} \ No newline at end of file diff --git a/HarmonyOS/Day4 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/DbUtils.java b/HarmonyOS/Day4 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/DbUtils.java new file mode 100644 index 00000000..89aac61c --- /dev/null +++ b/HarmonyOS/Day4 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/DbUtils.java @@ -0,0 +1,91 @@ +package com.example.trainingapp; + +import ohos.aafwk.ability.DataAbilityHelper; +import ohos.aafwk.ability.DataAbilityRemoteException; +import ohos.app.Context; +import ohos.data.dataability.DataAbilityPredicates; +import ohos.data.rdb.ValuesBucket; +import ohos.data.resultset.ResultSet; +import ohos.hiviewdfx.HiLog; +import ohos.hiviewdfx.HiLogLabel; +import ohos.utils.net.Uri; + +public class DbUtils { + private static final HiLogLabel LABEL_LOG = new HiLogLabel(3, 0xD001100, "DbUtils"); + + public static final String BASE_URI = "dataability:///com.example.trainingapp.PersonDataAbility"; + + public static final String DATA_PATH = "/person"; + + public static final String DB_COLUMN_PERSON_ID = "id"; + + public static final String DB_COLUMN_FIRSTNAME = "first_name"; + + public static final String DB_COLUMN_LASTNAME = "last_name"; + + public static final String DB_COLUMN_GENDER = "gender"; + + public static final String DB_COLUMN_EMAIL = "email"; + + public static final String DB_COLUMN_PASSWORD = "password"; + + public static final String DB_COLUMN_PHONE = "phone"; + + public static ResultSet query(Context context, DataAbilityPredicates predicates) { + DataAbilityHelper databaseHelper = DataAbilityHelper.creator(context); + + String[] columns = new String[] {DB_COLUMN_PERSON_ID, + DB_COLUMN_FIRSTNAME, DB_COLUMN_LASTNAME, DB_COLUMN_GENDER, DB_COLUMN_EMAIL, DB_COLUMN_PHONE, DB_COLUMN_PASSWORD}; + + ResultSet resultSet = null; + + try { + resultSet = databaseHelper.query(Uri.parse(BASE_URI + DATA_PATH), + columns, predicates); + } catch (IllegalStateException | DataAbilityRemoteException exception) { + HiLog.error(LABEL_LOG, "query: dataRemote exception | illegalStateException"); + } + return resultSet; + } + + public static void showDB(Context context) { + ResultSet resultSet = DbUtils.query(context, null); + if(resultSet == null) { + HiLog.error(LABEL_LOG, "resultset empty"); + return; + } + if(resultSet.getRowCount()==0) { + HiLog.error(LABEL_LOG, "row count 0"); + return; + } + + resultSet.goToFirstRow(); + do { + int id = resultSet.getInt(resultSet.getColumnIndexForName(DbUtils.DB_COLUMN_PERSON_ID)); + String name = resultSet.getString(resultSet.getColumnIndexForName(DbUtils.DB_COLUMN_FIRSTNAME)); + String email = resultSet.getString(resultSet.getColumnIndexForName(DbUtils.DB_COLUMN_EMAIL)); + String gender = resultSet.getString(resultSet.getColumnIndexForName(DbUtils.DB_COLUMN_GENDER)); + String password = resultSet.getString(resultSet.getColumnIndexForName(DbUtils.DB_COLUMN_PASSWORD)); + HiLog.info(LABEL_LOG, "query: Id :" + id + " Name :" + name + " Gender :" + gender + " Email :" + email + " Password :" + password); + } while (resultSet.goToNextRow()); + } + + public static void insert(Context context, String firstname, String lastname, String gender, String email, String phone, String password) { + DataAbilityHelper databaseHelper = DataAbilityHelper.creator(context); + + ValuesBucket valuesBucket = new ValuesBucket(); + valuesBucket.putString(DB_COLUMN_FIRSTNAME, firstname); + valuesBucket.putString(DB_COLUMN_LASTNAME, lastname); + valuesBucket.putString(DB_COLUMN_GENDER, gender); + valuesBucket.putString(DB_COLUMN_EMAIL, email); + valuesBucket.putString(DB_COLUMN_PHONE, phone); + valuesBucket.putString(DB_COLUMN_PASSWORD, password); + try { + if (databaseHelper.insert(Uri.parse(BASE_URI + DATA_PATH), valuesBucket) != -1) { + HiLog.info(LABEL_LOG, "insert successful"); + } + } catch (DataAbilityRemoteException | IllegalStateException exception) { + HiLog.error(LABEL_LOG, "insert: dataRemote exception|illegalStateException"); + } + } +} diff --git a/HarmonyOS/Day4 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/MainAbility.java b/HarmonyOS/Day4 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/MainAbility.java new file mode 100644 index 00000000..bf407ed6 --- /dev/null +++ b/HarmonyOS/Day4 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/MainAbility.java @@ -0,0 +1,13 @@ +package com.example.trainingapp; + +import com.example.trainingapp.slice.MainAbilitySlice; +import ohos.aafwk.ability.Ability; +import ohos.aafwk.content.Intent; + +public class MainAbility extends Ability { + @Override + public void onStart(Intent intent) { + super.onStart(intent); + super.setMainRoute(MainAbilitySlice.class.getName()); + } +} diff --git a/HarmonyOS/Day4 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/MyApplication.java b/HarmonyOS/Day4 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/MyApplication.java new file mode 100644 index 00000000..ecf61daa --- /dev/null +++ b/HarmonyOS/Day4 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/MyApplication.java @@ -0,0 +1,10 @@ +package com.example.trainingapp; + +import ohos.aafwk.ability.AbilityPackage; + +public class MyApplication extends AbilityPackage { + @Override + public void onInitialize() { + super.onInitialize(); + } +} diff --git a/HarmonyOS/Day4 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/PersonDataAbility.java b/HarmonyOS/Day4 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/PersonDataAbility.java new file mode 100644 index 00000000..236bcf77 --- /dev/null +++ b/HarmonyOS/Day4 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/PersonDataAbility.java @@ -0,0 +1,134 @@ +package com.example.trainingapp; + +import ohos.aafwk.ability.Ability; +import ohos.aafwk.ability.DataAbilityHelper; +import ohos.aafwk.content.Intent; +import ohos.data.DatabaseHelper; +import ohos.data.dataability.DataAbilityUtils; +import ohos.data.rdb.*; +import ohos.data.resultset.ResultSet; +import ohos.data.dataability.DataAbilityPredicates; +import ohos.hiviewdfx.HiLog; +import ohos.hiviewdfx.HiLogLabel; +import ohos.utils.net.Uri; +import ohos.utils.PacMap; + +import java.io.FileDescriptor; + +public class PersonDataAbility extends Ability { + private static final HiLogLabel LABEL_LOG = new HiLogLabel(3, 0xD001100, "PersonDataAbility"); + + private static final String DB_NAME = "persondataability.db"; + + private static final String DB_TAB_NAME = "person"; + + private static final String DB_COLUMN_PERSON_ID = "id"; + + private static final String DB_COLUMN_FIRSTNAME = "first_name"; + + private static final String DB_COLUMN_LASTNAME = "last_name"; + + private static final String DB_COLUMN_GENDER = "gender"; + + private static final String DB_COLUMN_EMAIL = "email"; + + private static final String DB_COLUMN_PASSWORD = "password"; + + private static final String DB_COLUMN_PHONE = "phone"; + + private static final int DB_VERSION = 1; + + private final StoreConfig config = StoreConfig.newDefaultConfig(DB_NAME); + + private RdbStore rdbStore; + + private final RdbOpenCallback rdbOpenCallback = new RdbOpenCallback() { + @Override + public void onCreate(RdbStore store) { + store.executeSql("create table if not exists " + + DB_TAB_NAME + " (" + + DB_COLUMN_PERSON_ID + " integer primary key autoincrement, " + + DB_COLUMN_FIRSTNAME + " text not null, " + + DB_COLUMN_LASTNAME + " text not null, " + + DB_COLUMN_GENDER + " text not null, " + + DB_COLUMN_EMAIL + " text not null, " + + DB_COLUMN_PHONE + " text not null, " + + DB_COLUMN_PASSWORD + " text not null)"); + } + + @Override + public void onUpgrade(RdbStore store, int oldVersion, int newVersion) { + } + }; + + @Override + public void onStart(Intent intent) { + super.onStart(intent); + HiLog.info(LABEL_LOG, "PersonDataAbility onStart"); + + DatabaseHelper databaseHelper = new DatabaseHelper(this); + rdbStore = databaseHelper.getRdbStore(config, DB_VERSION, rdbOpenCallback, null); + } + + @Override + public ResultSet query(Uri uri, String[] columns, DataAbilityPredicates predicates) { + RdbPredicates rdbPredicates = DataAbilityUtils.createRdbPredicates(predicates, DB_TAB_NAME); + ResultSet resultSet = rdbStore.query(rdbPredicates, columns); + if (resultSet == null) { + HiLog.info(LABEL_LOG, "resultSet is null"); + } + return resultSet; + } + + @Override + public int insert(Uri uri, ValuesBucket value) { + HiLog.info(LABEL_LOG, "PersonDataAbility insert"); + String path = uri.getLastPath(); + if (!"person".equals(path)) { + HiLog.info(LABEL_LOG, "DataAbility insert path is not matched"); + return -1; + } + ValuesBucket values = new ValuesBucket(); + values.putInteger(DB_COLUMN_PERSON_ID, value.getInteger(DB_COLUMN_PERSON_ID)); + values.putString(DB_COLUMN_FIRSTNAME, value.getString(DB_COLUMN_FIRSTNAME)); + values.putString(DB_COLUMN_LASTNAME, value.getString(DB_COLUMN_LASTNAME)); + values.putString(DB_COLUMN_GENDER, value.getString(DB_COLUMN_GENDER)); + values.putString(DB_COLUMN_EMAIL, value.getString(DB_COLUMN_EMAIL)); + values.putString(DB_COLUMN_PHONE, value.getString(DB_COLUMN_PHONE)); + values.putString(DB_COLUMN_PASSWORD, value.getString(DB_COLUMN_PASSWORD)); + + int index = (int) rdbStore.insert(DB_TAB_NAME, values); + DataAbilityHelper.creator(this, uri).notifyChange(uri); + return index; + } + + @Override + public int delete(Uri uri, DataAbilityPredicates predicates) { + return 0; + } + + @Override + public int update(Uri uri, ValuesBucket value, DataAbilityPredicates predicates) { + return 0; + } + + @Override + public FileDescriptor openFile(Uri uri, String mode) { + return null; + } + + @Override + public String[] getFileTypes(Uri uri, String mimeTypeFilter) { + return new String[0]; + } + + @Override + public PacMap call(String method, String arg, PacMap extras) { + return null; + } + + @Override + public String getType(Uri uri) { + return null; + } +} diff --git a/HarmonyOS/Day4 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/slice/LoginSlice.java b/HarmonyOS/Day4 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/slice/LoginSlice.java new file mode 100644 index 00000000..753076be --- /dev/null +++ b/HarmonyOS/Day4 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/slice/LoginSlice.java @@ -0,0 +1,63 @@ +package com.example.trainingapp.slice; + +import ohos.aafwk.ability.AbilitySlice; +import ohos.aafwk.content.Intent; +import com.example.trainingapp.ResourceTable; +import ohos.agp.components.Button; +import ohos.agp.components.Component; +import ohos.agp.components.Text; +import ohos.agp.components.TextField; +import ohos.hiviewdfx.HiLog; +import ohos.hiviewdfx.HiLogLabel; +import ohos.data.dataability.DataAbilityPredicates; +import com.example.trainingapp.DbUtils; +import ohos.data.resultset.ResultSet; + +public class LoginSlice extends AbilitySlice { + private static final HiLogLabel LABEL_LOG = new HiLogLabel(3, 0xD001100, "LoginSlice"); + + TextField email, password; + Text loginError; + Button loginBtn; + @Override + protected void onStart(Intent intent){ + super.onStart(intent); + super.setUIContent(ResourceTable.Layout_login); + + email = (TextField) findComponentById(ResourceTable.Id_emailLogin); + password = (TextField) findComponentById(ResourceTable.Id_passwordLogin); + loginError = (Text) findComponentById(ResourceTable.Id_loginError); + loginBtn = (Button) findComponentById(ResourceTable.Id_loginButton); + + loginBtn.setClickedListener(new Component.ClickedListener() { + @Override + public void onClick(Component component) { + validateUser(); + } + }); + } + + private void validateUser() { + loginError.setText(null); + DataAbilityPredicates predicates = new DataAbilityPredicates(); + predicates.equalTo(DbUtils.DB_COLUMN_EMAIL, email.getText()); + predicates.equalTo(DbUtils.DB_COLUMN_PASSWORD, password.getText()); + + ResultSet resultSet = DbUtils.query(this, predicates); + if(resultSet == null || resultSet.getRowCount()==0) { + HiLog.error(LABEL_LOG, "resultset empty || getrowcount = 0"); + loginError.setVisibility(Component.VISIBLE); + return; + } + + resultSet.goToFirstRow(); + int id = resultSet.getInt(resultSet.getColumnIndexForName(DbUtils.DB_COLUMN_PERSON_ID)); + String name = resultSet.getString(resultSet.getColumnIndexForName(DbUtils.DB_COLUMN_FIRSTNAME)); + String email = resultSet.getString(resultSet.getColumnIndexForName(DbUtils.DB_COLUMN_EMAIL)); + String gender = resultSet.getString(resultSet.getColumnIndexForName(DbUtils.DB_COLUMN_GENDER)); + HiLog.info(LABEL_LOG, "query: Id :" + id + " Name :" + name + " Gender :" + gender + " Email :" + email); + + present(new LoginSuccessSlice(), new Intent()); + + } +} diff --git a/HarmonyOS/Day4 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/slice/LoginSuccessSlice.java b/HarmonyOS/Day4 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/slice/LoginSuccessSlice.java new file mode 100644 index 00000000..c50ce89e --- /dev/null +++ b/HarmonyOS/Day4 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/slice/LoginSuccessSlice.java @@ -0,0 +1,13 @@ +package com.example.trainingapp.slice; + +import ohos.aafwk.ability.AbilitySlice; +import ohos.aafwk.content.Intent; +import com.example.trainingapp.ResourceTable; + +public class LoginSuccessSlice extends AbilitySlice { + @Override + protected void onStart(Intent intent){ + super.onStart(intent); + super.setUIContent(ResourceTable.Layout_login_success); + } +} diff --git a/HarmonyOS/Day4 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/slice/MainAbilitySlice.java b/HarmonyOS/Day4 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/slice/MainAbilitySlice.java new file mode 100644 index 00000000..8527312d --- /dev/null +++ b/HarmonyOS/Day4 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/slice/MainAbilitySlice.java @@ -0,0 +1,49 @@ +package com.example.trainingapp.slice; + +import com.example.trainingapp.ResourceTable; +import ohos.aafwk.ability.AbilitySlice; +import ohos.aafwk.content.Intent; +import ohos.agp.animation.AnimatorProperty; +import ohos.agp.components.Button; +import ohos.agp.components.Component; +import ohos.agp.components.Image; + +public class MainAbilitySlice extends AbilitySlice { + @Override + public void onStart(Intent intent) { + super.onStart(intent); + super.setUIContent(ResourceTable.Layout_ability_main); + + Button bt1 = (Button) findComponentById(ResourceTable.Id_log); + Button bt2 = (Button) findComponentById(ResourceTable.Id_sign); + + Image img = (Image) findComponentById(ResourceTable.Id_icon); + AnimatorProperty animatorProperty = img.createAnimatorProperty(); + animatorProperty.moveFromX(50).moveToX(50).rotate(180).alpha(0).setDuration(2500).setDelay(500).setLoopedCount(-1); + + img.setBindStateChangedListener(new Component.BindStateChangedListener() { + @Override + public void onComponentBoundToWindow(Component component) { + animatorProperty.start(); + } + + @Override + public void onComponentUnboundFromWindow(Component component) { + animatorProperty.stop(); + } + }); + + bt1.setClickedListener(listener -> present(new LoginSlice(), new Intent())); + bt2.setClickedListener(listener -> present(new SignupSlice(), new Intent())); + } + + @Override + public void onActive() { + super.onActive(); + } + + @Override + public void onForeground(Intent intent) { + super.onForeground(intent); + } +} diff --git a/HarmonyOS/Day4 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/slice/SignupSlice.java b/HarmonyOS/Day4 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/slice/SignupSlice.java new file mode 100644 index 00000000..118d856f --- /dev/null +++ b/HarmonyOS/Day4 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/slice/SignupSlice.java @@ -0,0 +1,136 @@ +package com.example.trainingapp.slice; + +import ohos.aafwk.ability.AbilitySlice; +import com.example.trainingapp.DbUtils; +import ohos.aafwk.content.Intent; +import com.example.trainingapp.ResourceTable; +import ohos.agp.components.*; +import java.util.regex.Pattern; +import ohos.hiviewdfx.HiLog; +import ohos.hiviewdfx.HiLogLabel; + +public class SignupSlice extends AbilitySlice { + private static final HiLogLabel LABEL_LOG = new HiLogLabel(3, 0xD001100, "SignupSlice"); + TextField firstName, lastName, email, password, mobile; + Text firstError, lastError, emailError, passError, mobileError, radioError; + RadioButton maleRadio,femaleRadio; + Button signupBtn; + @Override + protected void onStart(Intent intent){ + super.onStart(intent); + super.setUIContent(ResourceTable.Layout_signup); + + + firstName = (TextField) findComponentById(ResourceTable.Id_first_name); + lastName = (TextField) findComponentById((ResourceTable.Id_last_name)); + email = (TextField) findComponentById(ResourceTable.Id_email); + password = (TextField) findComponentById(ResourceTable.Id_password); + mobile = (TextField) findComponentById(ResourceTable.Id_phone); + + maleRadio = (RadioButton) findComponentById(ResourceTable.Id_male); + femaleRadio = (RadioButton) findComponentById(ResourceTable.Id_female); + + firstError = (Text) findComponentById(ResourceTable.Id_firstError); + lastError = (Text) findComponentById(ResourceTable.Id_lastError); + emailError = (Text) findComponentById(ResourceTable.Id_emailError); + passError = (Text) findComponentById(ResourceTable.Id_passwordError); + mobileError = (Text) findComponentById(ResourceTable.Id_phoneError); + radioError = (Text) findComponentById(ResourceTable.Id_radioError); + + signupBtn =(Button) findComponentById(ResourceTable.Id_signup); + + signupBtn.setClickedListener(new Component.ClickedListener() { + @Override + public void onClick(Component component) { + if(checkValidity() == true){ + String gender; + if(maleRadio.isChecked()) gender = "Male"; + else gender = "Female"; + DbUtils.insert(SignupSlice.this, firstName.getText(), lastName.getText(), gender, email.getText(), mobile.getText(), password.getText()); + HiLog.info(LABEL_LOG, "User registered"); + DbUtils.showDB(SignupSlice.this); + + present(new SignupSuccessSlice(), new Intent()); + } + } + }); + + } + public boolean isNameValid(TextField name){ + String str = name.getText(); + String regex = "[a-zA-Z]+"; + Pattern p = Pattern.compile(regex); + + return p.matcher(str).matches(); + } + + public boolean isEmailValid(TextField email){ + String str = email.getText(); + String regex = ".+@.+\\..+"; + Pattern p = Pattern.compile(regex); + + return p.matcher(str).matches(); + } + + public boolean isPhoneValid(TextField mobile){ + String str = mobile.getText(); + String regex = "[1-9][0-9]{9}"; + Pattern p = Pattern.compile(regex); + + return p.matcher(str).matches(); + } + + public boolean isPassValid(TextField password){ + String str = password.getText(); + String regex = ".{5,}"; + Pattern p = Pattern.compile(regex); + return p.matcher(str).matches(); + } + + public boolean checkValidity(){ + boolean b = true; + if(firstName.getText() == null || firstName.getText().isEmpty() || !isNameValid(firstName)){ + firstError.setVisibility(Component.VISIBLE); + b = false; + } + else{ + firstError.setVisibility(Component.INVISIBLE); + } + if(lastName.getText() == null || lastName.getText().isEmpty() || !isNameValid(lastName)){ + lastError.setVisibility(Component.VISIBLE); + b = false; + } + else{ + lastError.setVisibility(Component.INVISIBLE); + } + if(email.getText() == null || email.getText().isEmpty() || !isEmailValid(email)){ + emailError.setVisibility(Component.VISIBLE); + b = false; + } + else{ + emailError.setVisibility(Component.INVISIBLE); + } + if(mobile.getText() == null || mobile.getText().isEmpty() || !isPhoneValid(mobile)){ + mobileError.setVisibility(Component.VISIBLE); + b = false; + } + else{ + mobileError.setVisibility(Component.INVISIBLE); + } + if(password.getText() == null || password.getText().isEmpty() || !isPassValid(password)){ + passError.setVisibility(Component.VISIBLE); + b = false; + } + else{ + passError.setVisibility(Component.INVISIBLE); + } + if(!maleRadio.isChecked() && !femaleRadio.isChecked()){ + radioError.setVisibility(Component.VISIBLE); + b = false; + } + else{ + radioError.setVisibility(Component.INVISIBLE); + } + return b; + } +} diff --git a/HarmonyOS/Day4 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/slice/SignupSuccessSlice.java b/HarmonyOS/Day4 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/slice/SignupSuccessSlice.java new file mode 100644 index 00000000..93414cbe --- /dev/null +++ b/HarmonyOS/Day4 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/slice/SignupSuccessSlice.java @@ -0,0 +1,13 @@ +package com.example.trainingapp.slice; + +import ohos.aafwk.ability.AbilitySlice; +import ohos.aafwk.content.Intent; +import com.example.trainingapp.ResourceTable; + +public class SignupSuccessSlice extends AbilitySlice { + @Override + protected void onStart(Intent intent){ + super.onStart(intent); + super.setUIContent(ResourceTable.Layout_signup_success); + } +} diff --git a/HarmonyOS/Day4 Assingment/trainingApp/entry/src/main/resources/base/element/string.json b/HarmonyOS/Day4 Assingment/trainingApp/entry/src/main/resources/base/element/string.json new file mode 100644 index 00000000..fb02a338 --- /dev/null +++ b/HarmonyOS/Day4 Assingment/trainingApp/entry/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "app_name", + "value": "trainingApp" + }, + { + "name": "mainability_description", + "value": "Java_Phone_Empty Feature Ability" + }, + { + "name": "mainability_HelloWorld", + "value": "Hello World" + } + ] +} \ No newline at end of file diff --git a/HarmonyOS/Day4 Assingment/trainingApp/entry/src/main/resources/base/graphic/background_ability_main.xml b/HarmonyOS/Day4 Assingment/trainingApp/entry/src/main/resources/base/graphic/background_ability_main.xml new file mode 100644 index 00000000..c0c0a3df --- /dev/null +++ b/HarmonyOS/Day4 Assingment/trainingApp/entry/src/main/resources/base/graphic/background_ability_main.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/HarmonyOS/Day4 Assingment/trainingApp/entry/src/main/resources/base/layout/ability_main.xml b/HarmonyOS/Day4 Assingment/trainingApp/entry/src/main/resources/base/layout/ability_main.xml new file mode 100644 index 00000000..13cf948e --- /dev/null +++ b/HarmonyOS/Day4 Assingment/trainingApp/entry/src/main/resources/base/layout/ability_main.xml @@ -0,0 +1,52 @@ + + + + + + + + \ No newline at end of file diff --git a/HarmonyOS/Day4 Assingment/trainingApp/entry/src/main/resources/base/layout/login.xml b/HarmonyOS/Day4 Assingment/trainingApp/entry/src/main/resources/base/layout/login.xml new file mode 100644 index 00000000..f9fe34fb --- /dev/null +++ b/HarmonyOS/Day4 Assingment/trainingApp/entry/src/main/resources/base/layout/login.xml @@ -0,0 +1,73 @@ + + + + + + + + + + \ No newline at end of file diff --git a/HarmonyOS/Day4 Assingment/trainingApp/entry/src/main/resources/base/layout/login_success.xml b/HarmonyOS/Day4 Assingment/trainingApp/entry/src/main/resources/base/layout/login_success.xml new file mode 100644 index 00000000..11d27d8a --- /dev/null +++ b/HarmonyOS/Day4 Assingment/trainingApp/entry/src/main/resources/base/layout/login_success.xml @@ -0,0 +1,14 @@ + + + + + \ No newline at end of file diff --git a/HarmonyOS/Day4 Assingment/trainingApp/entry/src/main/resources/base/layout/signup.xml b/HarmonyOS/Day4 Assingment/trainingApp/entry/src/main/resources/base/layout/signup.xml new file mode 100644 index 00000000..9b0527a0 --- /dev/null +++ b/HarmonyOS/Day4 Assingment/trainingApp/entry/src/main/resources/base/layout/signup.xml @@ -0,0 +1,190 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/HarmonyOS/Day4 Assingment/trainingApp/entry/src/main/resources/base/layout/signup_success.xml b/HarmonyOS/Day4 Assingment/trainingApp/entry/src/main/resources/base/layout/signup_success.xml new file mode 100644 index 00000000..a362048b --- /dev/null +++ b/HarmonyOS/Day4 Assingment/trainingApp/entry/src/main/resources/base/layout/signup_success.xml @@ -0,0 +1,15 @@ + + + + + + \ No newline at end of file diff --git a/HarmonyOS/Day4 Assingment/trainingApp/entry/src/main/resources/base/media/icon.png b/HarmonyOS/Day4 Assingment/trainingApp/entry/src/main/resources/base/media/icon.png new file mode 100644 index 00000000..ce307a88 Binary files /dev/null and b/HarmonyOS/Day4 Assingment/trainingApp/entry/src/main/resources/base/media/icon.png differ diff --git a/HarmonyOS/Day4 Assingment/trainingApp/entry/src/ohosTest/config.json b/HarmonyOS/Day4 Assingment/trainingApp/entry/src/ohosTest/config.json new file mode 100644 index 00000000..0e29531e --- /dev/null +++ b/HarmonyOS/Day4 Assingment/trainingApp/entry/src/ohosTest/config.json @@ -0,0 +1,41 @@ +{ + "app": { + "bundleName": "com.example.trainingapp", + "vendor": "example", + "version": { + "code": 1000000, + "name": "1.0.0" + }, + "apiVersion": { + "compatible": 5, + "target": 5, + "releaseType": "Release" + } + }, + "deviceConfig": {}, + "module": { + "package": "com.example.trainingapp", + "name": "testModule", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry_test", + "moduleType": "feature", + "installationFree": true + }, + "abilities": [ + { + "name": "decc.testkit.runner.EntryAbility", + "description": "Test Entry Ability", + "icon": "$media:icon", + "label": "$string:app_name", + "launchType": "standard", + "orientation": "landscape", + "visible": true, + "type": "page" + } + ] + } +} \ No newline at end of file diff --git a/HarmonyOS/Day4 Assingment/trainingApp/entry/src/ohosTest/java/com/example/trainingapp/ExampleOhosTest.java b/HarmonyOS/Day4 Assingment/trainingApp/entry/src/ohosTest/java/com/example/trainingapp/ExampleOhosTest.java new file mode 100644 index 00000000..3340a0d6 --- /dev/null +++ b/HarmonyOS/Day4 Assingment/trainingApp/entry/src/ohosTest/java/com/example/trainingapp/ExampleOhosTest.java @@ -0,0 +1,14 @@ +package com.example.trainingapp; + +import ohos.aafwk.ability.delegation.AbilityDelegatorRegistry; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class ExampleOhosTest { + @Test + public void testBundleName() { + final String actualBundleName = AbilityDelegatorRegistry.getArguments().getTestBundleName(); + assertEquals("com.example.trainingapp", actualBundleName); + } +} \ No newline at end of file diff --git a/HarmonyOS/Day4 Assingment/trainingApp/entry/src/test/java/com/example/trainingapp/ExampleTest.java b/HarmonyOS/Day4 Assingment/trainingApp/entry/src/test/java/com/example/trainingapp/ExampleTest.java new file mode 100644 index 00000000..b047cceb --- /dev/null +++ b/HarmonyOS/Day4 Assingment/trainingApp/entry/src/test/java/com/example/trainingapp/ExampleTest.java @@ -0,0 +1,9 @@ +package com.example.trainingapp; + +import org.junit.Test; + +public class ExampleTest { + @Test + public void onStart() { + } +} diff --git a/HarmonyOS/Day4 Assingment/trainingApp/gradle.properties b/HarmonyOS/Day4 Assingment/trainingApp/gradle.properties new file mode 100644 index 00000000..0daf1830 --- /dev/null +++ b/HarmonyOS/Day4 Assingment/trainingApp/gradle.properties @@ -0,0 +1,10 @@ +# Project-wide Gradle settings. +# IDE (e.g. DevEco Studio) users: +# Gradle settings configured through the IDE *will override* +# any settings specified in this file. +# For more details on how to configure your build environment visit +# http://www.gradle.org/docs/current/userguide/build_environment.html +# Specifies the JVM arguments used for the daemon process. +# The setting is particularly useful for tweaking memory settings. +# If the Chinese output is garbled, please configure the following parameter. +# org.gradle.jvmargs=-Dfile.encoding=GBK diff --git a/HarmonyOS/Day4 Assingment/trainingApp/gradle/wrapper/gradle-wrapper.jar b/HarmonyOS/Day4 Assingment/trainingApp/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 00000000..490fda85 Binary files /dev/null and b/HarmonyOS/Day4 Assingment/trainingApp/gradle/wrapper/gradle-wrapper.jar differ diff --git a/HarmonyOS/Day4 Assingment/trainingApp/gradle/wrapper/gradle-wrapper.properties b/HarmonyOS/Day4 Assingment/trainingApp/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 00000000..f59159e8 --- /dev/null +++ b/HarmonyOS/Day4 Assingment/trainingApp/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://repo.huaweicloud.com/gradle/gradle-6.3-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/HarmonyOS/Day4 Assingment/trainingApp/gradlew b/HarmonyOS/Day4 Assingment/trainingApp/gradlew new file mode 100644 index 00000000..2fe81a7d --- /dev/null +++ b/HarmonyOS/Day4 Assingment/trainingApp/gradlew @@ -0,0 +1,183 @@ +#!/usr/bin/env sh + +# +# Copyright 2015 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin or MSYS, switch paths to Windows format before running java +if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=`expr $i + 1` + done + case $i in + 0) set -- ;; + 1) set -- "$args0" ;; + 2) set -- "$args0" "$args1" ;; + 3) set -- "$args0" "$args1" "$args2" ;; + 4) set -- "$args0" "$args1" "$args2" "$args3" ;; + 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=`save "$@"` + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +exec "$JAVACMD" "$@" diff --git a/HarmonyOS/Day4 Assingment/trainingApp/gradlew.bat b/HarmonyOS/Day4 Assingment/trainingApp/gradlew.bat new file mode 100644 index 00000000..62bd9b9c --- /dev/null +++ b/HarmonyOS/Day4 Assingment/trainingApp/gradlew.bat @@ -0,0 +1,103 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windows variants + +if not "%OS%" == "Windows_NT" goto win9xME_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/HarmonyOS/Day4 Assingment/trainingApp/settings.gradle b/HarmonyOS/Day4 Assingment/trainingApp/settings.gradle new file mode 100644 index 00000000..4773db73 --- /dev/null +++ b/HarmonyOS/Day4 Assingment/trainingApp/settings.gradle @@ -0,0 +1 @@ +include ':entry' diff --git a/HarmonyOS/Day5 Assingment/trainingApp/.gitignore b/HarmonyOS/Day5 Assingment/trainingApp/.gitignore new file mode 100644 index 00000000..37a4eb8b --- /dev/null +++ b/HarmonyOS/Day5 Assingment/trainingApp/.gitignore @@ -0,0 +1,15 @@ +*.iml +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store +/build +/captures +.externalNativeBuild +/entry/.preview +.cxx diff --git a/HarmonyOS/Day5 Assingment/trainingApp/.idea/.gitignore b/HarmonyOS/Day5 Assingment/trainingApp/.idea/.gitignore new file mode 100644 index 00000000..26d33521 --- /dev/null +++ b/HarmonyOS/Day5 Assingment/trainingApp/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/HarmonyOS/Day5 Assingment/trainingApp/.idea/compiler.xml b/HarmonyOS/Day5 Assingment/trainingApp/.idea/compiler.xml new file mode 100644 index 00000000..61a9130c --- /dev/null +++ b/HarmonyOS/Day5 Assingment/trainingApp/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/HarmonyOS/Day5 Assingment/trainingApp/.idea/gradle.xml b/HarmonyOS/Day5 Assingment/trainingApp/.idea/gradle.xml new file mode 100644 index 00000000..b9090f42 --- /dev/null +++ b/HarmonyOS/Day5 Assingment/trainingApp/.idea/gradle.xml @@ -0,0 +1,22 @@ + + + + + + + \ No newline at end of file diff --git a/HarmonyOS/Day5 Assingment/trainingApp/.idea/jarRepositories.xml b/HarmonyOS/Day5 Assingment/trainingApp/.idea/jarRepositories.xml new file mode 100644 index 00000000..1dfcd020 --- /dev/null +++ b/HarmonyOS/Day5 Assingment/trainingApp/.idea/jarRepositories.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/HarmonyOS/Day5 Assingment/trainingApp/.idea/misc.xml b/HarmonyOS/Day5 Assingment/trainingApp/.idea/misc.xml new file mode 100644 index 00000000..58918f50 --- /dev/null +++ b/HarmonyOS/Day5 Assingment/trainingApp/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/HarmonyOS/Day5 Assingment/trainingApp/.idea/previewer/phone/phoneSettingConfig_1825807532.json b/HarmonyOS/Day5 Assingment/trainingApp/.idea/previewer/phone/phoneSettingConfig_1825807532.json new file mode 100644 index 00000000..f505e6b9 --- /dev/null +++ b/HarmonyOS/Day5 Assingment/trainingApp/.idea/previewer/phone/phoneSettingConfig_1825807532.json @@ -0,0 +1,25 @@ +{ + "setting": { + "1.0.1": { + "Language": { + "args": { + "Language": "zh-CN" + } + } + } + }, + "frontend": { + "1.0.0": { + "Resolution": { + "args": { + "Resolution": "360*780" + } + }, + "DeviceType": { + "args": { + "DeviceType": "phone" + } + } + } + } +} \ No newline at end of file diff --git a/HarmonyOS/Day5 Assingment/trainingApp/.idea/previewer/previewConfig.json b/HarmonyOS/Day5 Assingment/trainingApp/.idea/previewer/previewConfig.json new file mode 100644 index 00000000..0c811855 --- /dev/null +++ b/HarmonyOS/Day5 Assingment/trainingApp/.idea/previewer/previewConfig.json @@ -0,0 +1,9 @@ +{ + "1.0.0": { + "LastPreviewDevice": { + "C:\\Users\\jjati\\DevEcoStudioProjects\\trainingApp\\entry": [ + "phone" + ] + } + } +} \ No newline at end of file diff --git a/HarmonyOS/Day5 Assingment/trainingApp/build.gradle b/HarmonyOS/Day5 Assingment/trainingApp/build.gradle new file mode 100644 index 00000000..1dc510ff --- /dev/null +++ b/HarmonyOS/Day5 Assingment/trainingApp/build.gradle @@ -0,0 +1,37 @@ +// Top-level build file where you can add configuration options common to all sub-projects/modules. +apply plugin: 'com.huawei.ohos.app' + +ohos { + compileSdkVersion 5 + defaultConfig { + compatibleSdkVersion 5 + } +} + +buildscript { + repositories { + maven { + url 'https://repo.huaweicloud.com/repository/maven/' + } + maven { + url 'https://developer.huawei.com/repo/' + } + jcenter() + } + dependencies { + classpath 'com.huawei.ohos:hap:2.4.2.7' + classpath 'com.huawei.ohos:decctest:1.0.0.7' + } +} + +allprojects { + repositories { + maven { + url 'https://repo.huaweicloud.com/repository/maven/' + } + maven { + url 'https://developer.huawei.com/repo/' + } + jcenter() + } +} diff --git a/HarmonyOS/Day5 Assingment/trainingApp/entry/.gitignore b/HarmonyOS/Day5 Assingment/trainingApp/entry/.gitignore new file mode 100644 index 00000000..796b96d1 --- /dev/null +++ b/HarmonyOS/Day5 Assingment/trainingApp/entry/.gitignore @@ -0,0 +1 @@ +/build diff --git a/HarmonyOS/Day5 Assingment/trainingApp/entry/build.gradle b/HarmonyOS/Day5 Assingment/trainingApp/entry/build.gradle new file mode 100644 index 00000000..752a0370 --- /dev/null +++ b/HarmonyOS/Day5 Assingment/trainingApp/entry/build.gradle @@ -0,0 +1,26 @@ +apply plugin: 'com.huawei.ohos.hap' +apply plugin: 'com.huawei.ohos.decctest' +ohos { + compileSdkVersion 5 + defaultConfig { + compatibleSdkVersion 5 + } + buildTypes { + release { + proguardOpt { + proguardEnabled false + rulesFiles 'proguard-rules.pro' + } + } + } + +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar', '*.har']) + testImplementation 'junit:junit:4.13' + ohosTestImplementation 'com.huawei.ohos.testkit:runner:1.0.0.100' +} +decc { + supportType = ['html','xml'] +} diff --git a/HarmonyOS/Day5 Assingment/trainingApp/entry/proguard-rules.pro b/HarmonyOS/Day5 Assingment/trainingApp/entry/proguard-rules.pro new file mode 100644 index 00000000..f7666e47 --- /dev/null +++ b/HarmonyOS/Day5 Assingment/trainingApp/entry/proguard-rules.pro @@ -0,0 +1 @@ +# config module specific ProGuard rules here. \ No newline at end of file diff --git a/HarmonyOS/Day5 Assingment/trainingApp/entry/src/main/config.json b/HarmonyOS/Day5 Assingment/trainingApp/entry/src/main/config.json new file mode 100644 index 00000000..83cb73f6 --- /dev/null +++ b/HarmonyOS/Day5 Assingment/trainingApp/entry/src/main/config.json @@ -0,0 +1,58 @@ +{ + "app": { + "bundleName": "com.example.trainingapp", + "vendor": "example", + "version": { + "code": 1000000, + "name": "1.0.0" + }, + "apiVersion": { + "compatible": 5, + "target": 5, + "releaseType": "Release" + } + }, + "deviceConfig": {}, + "module": { + "package": "com.example.trainingapp", + "name": ".MyApplication", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry", + "moduleType": "entry" + }, + "abilities": [ + { + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "orientation": "unspecified", + "name": "com.example.trainingapp.MainAbility", + "icon": "$media:icon", + "description": "$string:mainability_description", + "label": "$string:app_name", + "type": "page", + "launchType": "standard" + }, + { + "permissions": [ + "com.example.trainingapp.DataAbilityShellProvider.PROVIDER" + ], + "name": "com.example.trainingapp.PersonDataAbility", + "icon": "$media:icon", + "type": "data", + "uri": "dataability://com.example.trainingapp.PersonDataAbility" + } + ] + } +} \ No newline at end of file diff --git a/HarmonyOS/Day5 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/DbUtils.java b/HarmonyOS/Day5 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/DbUtils.java new file mode 100644 index 00000000..89aac61c --- /dev/null +++ b/HarmonyOS/Day5 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/DbUtils.java @@ -0,0 +1,91 @@ +package com.example.trainingapp; + +import ohos.aafwk.ability.DataAbilityHelper; +import ohos.aafwk.ability.DataAbilityRemoteException; +import ohos.app.Context; +import ohos.data.dataability.DataAbilityPredicates; +import ohos.data.rdb.ValuesBucket; +import ohos.data.resultset.ResultSet; +import ohos.hiviewdfx.HiLog; +import ohos.hiviewdfx.HiLogLabel; +import ohos.utils.net.Uri; + +public class DbUtils { + private static final HiLogLabel LABEL_LOG = new HiLogLabel(3, 0xD001100, "DbUtils"); + + public static final String BASE_URI = "dataability:///com.example.trainingapp.PersonDataAbility"; + + public static final String DATA_PATH = "/person"; + + public static final String DB_COLUMN_PERSON_ID = "id"; + + public static final String DB_COLUMN_FIRSTNAME = "first_name"; + + public static final String DB_COLUMN_LASTNAME = "last_name"; + + public static final String DB_COLUMN_GENDER = "gender"; + + public static final String DB_COLUMN_EMAIL = "email"; + + public static final String DB_COLUMN_PASSWORD = "password"; + + public static final String DB_COLUMN_PHONE = "phone"; + + public static ResultSet query(Context context, DataAbilityPredicates predicates) { + DataAbilityHelper databaseHelper = DataAbilityHelper.creator(context); + + String[] columns = new String[] {DB_COLUMN_PERSON_ID, + DB_COLUMN_FIRSTNAME, DB_COLUMN_LASTNAME, DB_COLUMN_GENDER, DB_COLUMN_EMAIL, DB_COLUMN_PHONE, DB_COLUMN_PASSWORD}; + + ResultSet resultSet = null; + + try { + resultSet = databaseHelper.query(Uri.parse(BASE_URI + DATA_PATH), + columns, predicates); + } catch (IllegalStateException | DataAbilityRemoteException exception) { + HiLog.error(LABEL_LOG, "query: dataRemote exception | illegalStateException"); + } + return resultSet; + } + + public static void showDB(Context context) { + ResultSet resultSet = DbUtils.query(context, null); + if(resultSet == null) { + HiLog.error(LABEL_LOG, "resultset empty"); + return; + } + if(resultSet.getRowCount()==0) { + HiLog.error(LABEL_LOG, "row count 0"); + return; + } + + resultSet.goToFirstRow(); + do { + int id = resultSet.getInt(resultSet.getColumnIndexForName(DbUtils.DB_COLUMN_PERSON_ID)); + String name = resultSet.getString(resultSet.getColumnIndexForName(DbUtils.DB_COLUMN_FIRSTNAME)); + String email = resultSet.getString(resultSet.getColumnIndexForName(DbUtils.DB_COLUMN_EMAIL)); + String gender = resultSet.getString(resultSet.getColumnIndexForName(DbUtils.DB_COLUMN_GENDER)); + String password = resultSet.getString(resultSet.getColumnIndexForName(DbUtils.DB_COLUMN_PASSWORD)); + HiLog.info(LABEL_LOG, "query: Id :" + id + " Name :" + name + " Gender :" + gender + " Email :" + email + " Password :" + password); + } while (resultSet.goToNextRow()); + } + + public static void insert(Context context, String firstname, String lastname, String gender, String email, String phone, String password) { + DataAbilityHelper databaseHelper = DataAbilityHelper.creator(context); + + ValuesBucket valuesBucket = new ValuesBucket(); + valuesBucket.putString(DB_COLUMN_FIRSTNAME, firstname); + valuesBucket.putString(DB_COLUMN_LASTNAME, lastname); + valuesBucket.putString(DB_COLUMN_GENDER, gender); + valuesBucket.putString(DB_COLUMN_EMAIL, email); + valuesBucket.putString(DB_COLUMN_PHONE, phone); + valuesBucket.putString(DB_COLUMN_PASSWORD, password); + try { + if (databaseHelper.insert(Uri.parse(BASE_URI + DATA_PATH), valuesBucket) != -1) { + HiLog.info(LABEL_LOG, "insert successful"); + } + } catch (DataAbilityRemoteException | IllegalStateException exception) { + HiLog.error(LABEL_LOG, "insert: dataRemote exception|illegalStateException"); + } + } +} diff --git a/HarmonyOS/Day5 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/MainAbility.java b/HarmonyOS/Day5 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/MainAbility.java new file mode 100644 index 00000000..bf407ed6 --- /dev/null +++ b/HarmonyOS/Day5 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/MainAbility.java @@ -0,0 +1,13 @@ +package com.example.trainingapp; + +import com.example.trainingapp.slice.MainAbilitySlice; +import ohos.aafwk.ability.Ability; +import ohos.aafwk.content.Intent; + +public class MainAbility extends Ability { + @Override + public void onStart(Intent intent) { + super.onStart(intent); + super.setMainRoute(MainAbilitySlice.class.getName()); + } +} diff --git a/HarmonyOS/Day5 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/MyApplication.java b/HarmonyOS/Day5 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/MyApplication.java new file mode 100644 index 00000000..ecf61daa --- /dev/null +++ b/HarmonyOS/Day5 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/MyApplication.java @@ -0,0 +1,10 @@ +package com.example.trainingapp; + +import ohos.aafwk.ability.AbilityPackage; + +public class MyApplication extends AbilityPackage { + @Override + public void onInitialize() { + super.onInitialize(); + } +} diff --git a/HarmonyOS/Day5 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/PersonDataAbility.java b/HarmonyOS/Day5 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/PersonDataAbility.java new file mode 100644 index 00000000..236bcf77 --- /dev/null +++ b/HarmonyOS/Day5 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/PersonDataAbility.java @@ -0,0 +1,134 @@ +package com.example.trainingapp; + +import ohos.aafwk.ability.Ability; +import ohos.aafwk.ability.DataAbilityHelper; +import ohos.aafwk.content.Intent; +import ohos.data.DatabaseHelper; +import ohos.data.dataability.DataAbilityUtils; +import ohos.data.rdb.*; +import ohos.data.resultset.ResultSet; +import ohos.data.dataability.DataAbilityPredicates; +import ohos.hiviewdfx.HiLog; +import ohos.hiviewdfx.HiLogLabel; +import ohos.utils.net.Uri; +import ohos.utils.PacMap; + +import java.io.FileDescriptor; + +public class PersonDataAbility extends Ability { + private static final HiLogLabel LABEL_LOG = new HiLogLabel(3, 0xD001100, "PersonDataAbility"); + + private static final String DB_NAME = "persondataability.db"; + + private static final String DB_TAB_NAME = "person"; + + private static final String DB_COLUMN_PERSON_ID = "id"; + + private static final String DB_COLUMN_FIRSTNAME = "first_name"; + + private static final String DB_COLUMN_LASTNAME = "last_name"; + + private static final String DB_COLUMN_GENDER = "gender"; + + private static final String DB_COLUMN_EMAIL = "email"; + + private static final String DB_COLUMN_PASSWORD = "password"; + + private static final String DB_COLUMN_PHONE = "phone"; + + private static final int DB_VERSION = 1; + + private final StoreConfig config = StoreConfig.newDefaultConfig(DB_NAME); + + private RdbStore rdbStore; + + private final RdbOpenCallback rdbOpenCallback = new RdbOpenCallback() { + @Override + public void onCreate(RdbStore store) { + store.executeSql("create table if not exists " + + DB_TAB_NAME + " (" + + DB_COLUMN_PERSON_ID + " integer primary key autoincrement, " + + DB_COLUMN_FIRSTNAME + " text not null, " + + DB_COLUMN_LASTNAME + " text not null, " + + DB_COLUMN_GENDER + " text not null, " + + DB_COLUMN_EMAIL + " text not null, " + + DB_COLUMN_PHONE + " text not null, " + + DB_COLUMN_PASSWORD + " text not null)"); + } + + @Override + public void onUpgrade(RdbStore store, int oldVersion, int newVersion) { + } + }; + + @Override + public void onStart(Intent intent) { + super.onStart(intent); + HiLog.info(LABEL_LOG, "PersonDataAbility onStart"); + + DatabaseHelper databaseHelper = new DatabaseHelper(this); + rdbStore = databaseHelper.getRdbStore(config, DB_VERSION, rdbOpenCallback, null); + } + + @Override + public ResultSet query(Uri uri, String[] columns, DataAbilityPredicates predicates) { + RdbPredicates rdbPredicates = DataAbilityUtils.createRdbPredicates(predicates, DB_TAB_NAME); + ResultSet resultSet = rdbStore.query(rdbPredicates, columns); + if (resultSet == null) { + HiLog.info(LABEL_LOG, "resultSet is null"); + } + return resultSet; + } + + @Override + public int insert(Uri uri, ValuesBucket value) { + HiLog.info(LABEL_LOG, "PersonDataAbility insert"); + String path = uri.getLastPath(); + if (!"person".equals(path)) { + HiLog.info(LABEL_LOG, "DataAbility insert path is not matched"); + return -1; + } + ValuesBucket values = new ValuesBucket(); + values.putInteger(DB_COLUMN_PERSON_ID, value.getInteger(DB_COLUMN_PERSON_ID)); + values.putString(DB_COLUMN_FIRSTNAME, value.getString(DB_COLUMN_FIRSTNAME)); + values.putString(DB_COLUMN_LASTNAME, value.getString(DB_COLUMN_LASTNAME)); + values.putString(DB_COLUMN_GENDER, value.getString(DB_COLUMN_GENDER)); + values.putString(DB_COLUMN_EMAIL, value.getString(DB_COLUMN_EMAIL)); + values.putString(DB_COLUMN_PHONE, value.getString(DB_COLUMN_PHONE)); + values.putString(DB_COLUMN_PASSWORD, value.getString(DB_COLUMN_PASSWORD)); + + int index = (int) rdbStore.insert(DB_TAB_NAME, values); + DataAbilityHelper.creator(this, uri).notifyChange(uri); + return index; + } + + @Override + public int delete(Uri uri, DataAbilityPredicates predicates) { + return 0; + } + + @Override + public int update(Uri uri, ValuesBucket value, DataAbilityPredicates predicates) { + return 0; + } + + @Override + public FileDescriptor openFile(Uri uri, String mode) { + return null; + } + + @Override + public String[] getFileTypes(Uri uri, String mimeTypeFilter) { + return new String[0]; + } + + @Override + public PacMap call(String method, String arg, PacMap extras) { + return null; + } + + @Override + public String getType(Uri uri) { + return null; + } +} diff --git a/HarmonyOS/Day5 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/slice/LoginSlice.java b/HarmonyOS/Day5 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/slice/LoginSlice.java new file mode 100644 index 00000000..15462d4a --- /dev/null +++ b/HarmonyOS/Day5 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/slice/LoginSlice.java @@ -0,0 +1,82 @@ +package com.example.trainingapp.slice; + +import ohos.aafwk.ability.AbilitySlice; +import ohos.aafwk.content.Intent; +import com.example.trainingapp.ResourceTable; +import ohos.agp.components.Button; +import ohos.agp.components.Component; +import ohos.agp.components.Text; +import ohos.agp.components.TextField; +import ohos.hiviewdfx.HiLog; +import ohos.hiviewdfx.HiLogLabel; +import ohos.data.dataability.DataAbilityPredicates; +import com.example.trainingapp.DbUtils; +import ohos.data.resultset.ResultSet; +import ohos.agp.window.dialog.ToastDialog; + +public class LoginSlice extends AbilitySlice { + private static final HiLogLabel LABEL_LOG = new HiLogLabel(3, 0xD001100, "LoginSlice"); + + TextField email, password; + Text loginError; + Button loginBtn; + @Override + protected void onStart(Intent intent){ + super.onStart(intent); + super.setUIContent(ResourceTable.Layout_login); + + String email_intent = intent.getStringParam("email"); + String password_intent = intent.getStringParam("password"); + + email = (TextField) findComponentById(ResourceTable.Id_emailLogin); + password = (TextField) findComponentById(ResourceTable.Id_passwordLogin); + loginError = (Text) findComponentById(ResourceTable.Id_loginError); + loginBtn = (Button) findComponentById(ResourceTable.Id_loginButton); + + if (email_intent != null) { + email.setText(email_intent); + } + + if (password_intent != null) { + password.setText(password_intent); + } + + loginBtn.setClickedListener(new Component.ClickedListener() { + @Override + public void onClick(Component component) { + validateUser(); + } + }); + } + + private void validateUser() { + loginError.setText(null); + DataAbilityPredicates predicates = new DataAbilityPredicates(); + predicates.equalTo(DbUtils.DB_COLUMN_EMAIL, email.getText()); + predicates.equalTo(DbUtils.DB_COLUMN_PASSWORD, password.getText()); + + ResultSet resultSet = DbUtils.query(this, predicates); + if(resultSet == null || resultSet.getRowCount()==0) { + HiLog.error(LABEL_LOG, "resultset empty || getrowcount = 0"); + loginError.setVisibility(Component.VISIBLE); + new ToastDialog(getContext()) + .setText("Invalid username/password") + .show(); + return; + } + + resultSet.goToFirstRow(); + int id = resultSet.getInt(resultSet.getColumnIndexForName(DbUtils.DB_COLUMN_PERSON_ID)); + String name = resultSet.getString(resultSet.getColumnIndexForName(DbUtils.DB_COLUMN_FIRSTNAME)); + String email = resultSet.getString(resultSet.getColumnIndexForName(DbUtils.DB_COLUMN_EMAIL)); + String gender = resultSet.getString(resultSet.getColumnIndexForName(DbUtils.DB_COLUMN_GENDER)); + HiLog.info(LABEL_LOG, "query: Id :" + id + " Name :" + name + " Gender :" + gender + " Email :" + email); + + new ToastDialog(getContext()) + .setText("Login Successful") + .show(); + + present(new LoginSuccessSlice(), new Intent()); + + } +} diff --git a/HarmonyOS/Day5 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/slice/LoginSuccessSlice.java b/HarmonyOS/Day5 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/slice/LoginSuccessSlice.java new file mode 100644 index 00000000..c50ce89e --- /dev/null +++ b/HarmonyOS/Day5 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/slice/LoginSuccessSlice.java @@ -0,0 +1,13 @@ +package com.example.trainingapp.slice; + +import ohos.aafwk.ability.AbilitySlice; +import ohos.aafwk.content.Intent; +import com.example.trainingapp.ResourceTable; + +public class LoginSuccessSlice extends AbilitySlice { + @Override + protected void onStart(Intent intent){ + super.onStart(intent); + super.setUIContent(ResourceTable.Layout_login_success); + } +} diff --git a/HarmonyOS/Day5 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/slice/MainAbilitySlice.java b/HarmonyOS/Day5 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/slice/MainAbilitySlice.java new file mode 100644 index 00000000..8527312d --- /dev/null +++ b/HarmonyOS/Day5 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/slice/MainAbilitySlice.java @@ -0,0 +1,49 @@ +package com.example.trainingapp.slice; + +import com.example.trainingapp.ResourceTable; +import ohos.aafwk.ability.AbilitySlice; +import ohos.aafwk.content.Intent; +import ohos.agp.animation.AnimatorProperty; +import ohos.agp.components.Button; +import ohos.agp.components.Component; +import ohos.agp.components.Image; + +public class MainAbilitySlice extends AbilitySlice { + @Override + public void onStart(Intent intent) { + super.onStart(intent); + super.setUIContent(ResourceTable.Layout_ability_main); + + Button bt1 = (Button) findComponentById(ResourceTable.Id_log); + Button bt2 = (Button) findComponentById(ResourceTable.Id_sign); + + Image img = (Image) findComponentById(ResourceTable.Id_icon); + AnimatorProperty animatorProperty = img.createAnimatorProperty(); + animatorProperty.moveFromX(50).moveToX(50).rotate(180).alpha(0).setDuration(2500).setDelay(500).setLoopedCount(-1); + + img.setBindStateChangedListener(new Component.BindStateChangedListener() { + @Override + public void onComponentBoundToWindow(Component component) { + animatorProperty.start(); + } + + @Override + public void onComponentUnboundFromWindow(Component component) { + animatorProperty.stop(); + } + }); + + bt1.setClickedListener(listener -> present(new LoginSlice(), new Intent())); + bt2.setClickedListener(listener -> present(new SignupSlice(), new Intent())); + } + + @Override + public void onActive() { + super.onActive(); + } + + @Override + public void onForeground(Intent intent) { + super.onForeground(intent); + } +} diff --git a/HarmonyOS/Day5 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/slice/SignupSlice.java b/HarmonyOS/Day5 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/slice/SignupSlice.java new file mode 100644 index 00000000..43430a22 --- /dev/null +++ b/HarmonyOS/Day5 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/slice/SignupSlice.java @@ -0,0 +1,165 @@ +package com.example.trainingapp.slice; + +import ohos.aafwk.ability.AbilitySlice; +import com.example.trainingapp.DbUtils; +import ohos.aafwk.content.Intent; +import com.example.trainingapp.ResourceTable; +import ohos.agp.components.*; +import java.util.regex.Pattern; + +import ohos.agp.window.dialog.CommonDialog; +import ohos.agp.window.dialog.IDialog; +import ohos.agp.window.dialog.ToastDialog; +import ohos.hiviewdfx.HiLog; +import ohos.hiviewdfx.HiLogLabel; + +import static ohos.agp.components.ComponentContainer.LayoutConfig.MATCH_CONTENT; + +public class SignupSlice extends AbilitySlice { + private static final HiLogLabel LABEL_LOG = new HiLogLabel(3, 0xD001100, "SignupSlice"); + TextField firstName, lastName, email, password, mobile; + Text firstError, lastError, emailError, passError, mobileError, radioError; + RadioButton maleRadio,femaleRadio; + Button signupBtn; + @Override + protected void onStart(Intent intent){ + super.onStart(intent); + super.setUIContent(ResourceTable.Layout_signup); + + + firstName = (TextField) findComponentById(ResourceTable.Id_first_name); + lastName = (TextField) findComponentById((ResourceTable.Id_last_name)); + email = (TextField) findComponentById(ResourceTable.Id_email); + password = (TextField) findComponentById(ResourceTable.Id_password); + mobile = (TextField) findComponentById(ResourceTable.Id_phone); + + maleRadio = (RadioButton) findComponentById(ResourceTable.Id_male); + femaleRadio = (RadioButton) findComponentById(ResourceTable.Id_female); + + firstError = (Text) findComponentById(ResourceTable.Id_firstError); + lastError = (Text) findComponentById(ResourceTable.Id_lastError); + emailError = (Text) findComponentById(ResourceTable.Id_emailError); + passError = (Text) findComponentById(ResourceTable.Id_passwordError); + mobileError = (Text) findComponentById(ResourceTable.Id_phoneError); + radioError = (Text) findComponentById(ResourceTable.Id_radioError); + + signupBtn =(Button) findComponentById(ResourceTable.Id_signup); + + signupBtn.setClickedListener(new Component.ClickedListener() { + @Override + public void onClick(Component component) { + if(checkValidity() == true){ + String gender; + if(maleRadio.isChecked()) gender = "Male"; + else gender = "Female"; + DbUtils.insert(SignupSlice.this, firstName.getText(), lastName.getText(), gender, email.getText(), mobile.getText(), password.getText()); + HiLog.info(LABEL_LOG, "User registered"); + DbUtils.showDB(SignupSlice.this); + + CommonDialog commonDialog = new CommonDialog(SignupSlice.this); + commonDialog.setTitleText("Common Dialog"); + commonDialog.setContentText("Login now?"); + commonDialog.setAutoClosable(true); + commonDialog.setSize(1000, MATCH_CONTENT); + commonDialog.setButton(IDialog.BUTTON1, "Yes", (iDialog, i) -> { + Intent intent1 = new Intent(); + intent1.setParam("email", email.getText()); + intent1.setParam("password", password.getText()); + present(new LoginSlice(), intent1); + iDialog.destroy(); + }); + commonDialog.setButton(IDialog.BUTTON2, "No", (iDialog, i) -> { + present(new SignupSuccessSlice(), new Intent()); + iDialog.destroy(); + }); + commonDialog.show(); + } + else { + new ToastDialog(getContext()) + .setText("Invalid parameters") + .show(); + + + } + } + }); + + } + public boolean isNameValid(TextField name){ + String str = name.getText(); + String regex = "[a-zA-Z]+"; + Pattern p = Pattern.compile(regex); + + return p.matcher(str).matches(); + } + + public boolean isEmailValid(TextField email){ + String str = email.getText(); + String regex = ".+@.+\\..+"; + Pattern p = Pattern.compile(regex); + + return p.matcher(str).matches(); + } + + public boolean isPhoneValid(TextField mobile){ + String str = mobile.getText(); + String regex = "[1-9][0-9]{9}"; + Pattern p = Pattern.compile(regex); + + return p.matcher(str).matches(); + } + + public boolean isPassValid(TextField password){ + String str = password.getText(); + String regex = ".{5,}"; + Pattern p = Pattern.compile(regex); + return p.matcher(str).matches(); + } + + public boolean checkValidity(){ + boolean b = true; + if(firstName.getText() == null || firstName.getText().isEmpty() || !isNameValid(firstName)){ + firstError.setVisibility(Component.VISIBLE); + b = false; + } + else{ + firstError.setVisibility(Component.INVISIBLE); + } + if(lastName.getText() == null || lastName.getText().isEmpty() || !isNameValid(lastName)){ + lastError.setVisibility(Component.VISIBLE); + b = false; + } + else{ + lastError.setVisibility(Component.INVISIBLE); + } + if(email.getText() == null || email.getText().isEmpty() || !isEmailValid(email)){ + emailError.setVisibility(Component.VISIBLE); + b = false; + } + else{ + emailError.setVisibility(Component.INVISIBLE); + } + if(mobile.getText() == null || mobile.getText().isEmpty() || !isPhoneValid(mobile)){ + mobileError.setVisibility(Component.VISIBLE); + b = false; + } + else{ + mobileError.setVisibility(Component.INVISIBLE); + } + if(password.getText() == null || password.getText().isEmpty() || !isPassValid(password)){ + passError.setVisibility(Component.VISIBLE); + b = false; + } + else{ + passError.setVisibility(Component.INVISIBLE); + } + if(!maleRadio.isChecked() && !femaleRadio.isChecked()){ + radioError.setVisibility(Component.VISIBLE); + b = false; + } + else{ + radioError.setVisibility(Component.INVISIBLE); + } + return b; + } +} diff --git a/HarmonyOS/Day5 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/slice/SignupSuccessSlice.java b/HarmonyOS/Day5 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/slice/SignupSuccessSlice.java new file mode 100644 index 00000000..93414cbe --- /dev/null +++ b/HarmonyOS/Day5 Assingment/trainingApp/entry/src/main/java/com/example/trainingapp/slice/SignupSuccessSlice.java @@ -0,0 +1,13 @@ +package com.example.trainingapp.slice; + +import ohos.aafwk.ability.AbilitySlice; +import ohos.aafwk.content.Intent; +import com.example.trainingapp.ResourceTable; + +public class SignupSuccessSlice extends AbilitySlice { + @Override + protected void onStart(Intent intent){ + super.onStart(intent); + super.setUIContent(ResourceTable.Layout_signup_success); + } +} diff --git a/HarmonyOS/Day5 Assingment/trainingApp/entry/src/main/resources/base/element/string.json b/HarmonyOS/Day5 Assingment/trainingApp/entry/src/main/resources/base/element/string.json new file mode 100644 index 00000000..fb02a338 --- /dev/null +++ b/HarmonyOS/Day5 Assingment/trainingApp/entry/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "app_name", + "value": "trainingApp" + }, + { + "name": "mainability_description", + "value": "Java_Phone_Empty Feature Ability" + }, + { + "name": "mainability_HelloWorld", + "value": "Hello World" + } + ] +} \ No newline at end of file diff --git a/HarmonyOS/Day5 Assingment/trainingApp/entry/src/main/resources/base/graphic/background_ability_main.xml b/HarmonyOS/Day5 Assingment/trainingApp/entry/src/main/resources/base/graphic/background_ability_main.xml new file mode 100644 index 00000000..c0c0a3df --- /dev/null +++ b/HarmonyOS/Day5 Assingment/trainingApp/entry/src/main/resources/base/graphic/background_ability_main.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/HarmonyOS/Day5 Assingment/trainingApp/entry/src/main/resources/base/layout/ability_main.xml b/HarmonyOS/Day5 Assingment/trainingApp/entry/src/main/resources/base/layout/ability_main.xml new file mode 100644 index 00000000..13cf948e --- /dev/null +++ b/HarmonyOS/Day5 Assingment/trainingApp/entry/src/main/resources/base/layout/ability_main.xml @@ -0,0 +1,52 @@ + + + + + + + + \ No newline at end of file diff --git a/HarmonyOS/Day5 Assingment/trainingApp/entry/src/main/resources/base/layout/login.xml b/HarmonyOS/Day5 Assingment/trainingApp/entry/src/main/resources/base/layout/login.xml new file mode 100644 index 00000000..f9fe34fb --- /dev/null +++ b/HarmonyOS/Day5 Assingment/trainingApp/entry/src/main/resources/base/layout/login.xml @@ -0,0 +1,73 @@ + + + + + + + + + + \ No newline at end of file diff --git a/HarmonyOS/Day5 Assingment/trainingApp/entry/src/main/resources/base/layout/login_success.xml b/HarmonyOS/Day5 Assingment/trainingApp/entry/src/main/resources/base/layout/login_success.xml new file mode 100644 index 00000000..11d27d8a --- /dev/null +++ b/HarmonyOS/Day5 Assingment/trainingApp/entry/src/main/resources/base/layout/login_success.xml @@ -0,0 +1,14 @@ + + + + + \ No newline at end of file diff --git a/HarmonyOS/Day5 Assingment/trainingApp/entry/src/main/resources/base/layout/signup.xml b/HarmonyOS/Day5 Assingment/trainingApp/entry/src/main/resources/base/layout/signup.xml new file mode 100644 index 00000000..9b0527a0 --- /dev/null +++ b/HarmonyOS/Day5 Assingment/trainingApp/entry/src/main/resources/base/layout/signup.xml @@ -0,0 +1,190 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/HarmonyOS/Day5 Assingment/trainingApp/entry/src/main/resources/base/layout/signup_success.xml b/HarmonyOS/Day5 Assingment/trainingApp/entry/src/main/resources/base/layout/signup_success.xml new file mode 100644 index 00000000..a362048b --- /dev/null +++ b/HarmonyOS/Day5 Assingment/trainingApp/entry/src/main/resources/base/layout/signup_success.xml @@ -0,0 +1,15 @@ + + + + + + \ No newline at end of file diff --git a/HarmonyOS/Day5 Assingment/trainingApp/entry/src/main/resources/base/media/icon.png b/HarmonyOS/Day5 Assingment/trainingApp/entry/src/main/resources/base/media/icon.png new file mode 100644 index 00000000..ce307a88 Binary files /dev/null and b/HarmonyOS/Day5 Assingment/trainingApp/entry/src/main/resources/base/media/icon.png differ diff --git a/HarmonyOS/Day5 Assingment/trainingApp/entry/src/ohosTest/config.json b/HarmonyOS/Day5 Assingment/trainingApp/entry/src/ohosTest/config.json new file mode 100644 index 00000000..0e29531e --- /dev/null +++ b/HarmonyOS/Day5 Assingment/trainingApp/entry/src/ohosTest/config.json @@ -0,0 +1,41 @@ +{ + "app": { + "bundleName": "com.example.trainingapp", + "vendor": "example", + "version": { + "code": 1000000, + "name": "1.0.0" + }, + "apiVersion": { + "compatible": 5, + "target": 5, + "releaseType": "Release" + } + }, + "deviceConfig": {}, + "module": { + "package": "com.example.trainingapp", + "name": "testModule", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry_test", + "moduleType": "feature", + "installationFree": true + }, + "abilities": [ + { + "name": "decc.testkit.runner.EntryAbility", + "description": "Test Entry Ability", + "icon": "$media:icon", + "label": "$string:app_name", + "launchType": "standard", + "orientation": "landscape", + "visible": true, + "type": "page" + } + ] + } +} \ No newline at end of file diff --git a/HarmonyOS/Day5 Assingment/trainingApp/entry/src/ohosTest/java/com/example/trainingapp/ExampleOhosTest.java b/HarmonyOS/Day5 Assingment/trainingApp/entry/src/ohosTest/java/com/example/trainingapp/ExampleOhosTest.java new file mode 100644 index 00000000..3340a0d6 --- /dev/null +++ b/HarmonyOS/Day5 Assingment/trainingApp/entry/src/ohosTest/java/com/example/trainingapp/ExampleOhosTest.java @@ -0,0 +1,14 @@ +package com.example.trainingapp; + +import ohos.aafwk.ability.delegation.AbilityDelegatorRegistry; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class ExampleOhosTest { + @Test + public void testBundleName() { + final String actualBundleName = AbilityDelegatorRegistry.getArguments().getTestBundleName(); + assertEquals("com.example.trainingapp", actualBundleName); + } +} \ No newline at end of file diff --git a/HarmonyOS/Day5 Assingment/trainingApp/entry/src/test/java/com/example/trainingapp/ExampleTest.java b/HarmonyOS/Day5 Assingment/trainingApp/entry/src/test/java/com/example/trainingapp/ExampleTest.java new file mode 100644 index 00000000..b047cceb --- /dev/null +++ b/HarmonyOS/Day5 Assingment/trainingApp/entry/src/test/java/com/example/trainingapp/ExampleTest.java @@ -0,0 +1,9 @@ +package com.example.trainingapp; + +import org.junit.Test; + +public class ExampleTest { + @Test + public void onStart() { + } +} diff --git a/HarmonyOS/Day5 Assingment/trainingApp/gradle.properties b/HarmonyOS/Day5 Assingment/trainingApp/gradle.properties new file mode 100644 index 00000000..0daf1830 --- /dev/null +++ b/HarmonyOS/Day5 Assingment/trainingApp/gradle.properties @@ -0,0 +1,10 @@ +# Project-wide Gradle settings. +# IDE (e.g. DevEco Studio) users: +# Gradle settings configured through the IDE *will override* +# any settings specified in this file. +# For more details on how to configure your build environment visit +# http://www.gradle.org/docs/current/userguide/build_environment.html +# Specifies the JVM arguments used for the daemon process. +# The setting is particularly useful for tweaking memory settings. +# If the Chinese output is garbled, please configure the following parameter. +# org.gradle.jvmargs=-Dfile.encoding=GBK diff --git a/HarmonyOS/Day5 Assingment/trainingApp/gradle/wrapper/gradle-wrapper.jar b/HarmonyOS/Day5 Assingment/trainingApp/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 00000000..490fda85 Binary files /dev/null and b/HarmonyOS/Day5 Assingment/trainingApp/gradle/wrapper/gradle-wrapper.jar differ diff --git a/HarmonyOS/Day5 Assingment/trainingApp/gradle/wrapper/gradle-wrapper.properties b/HarmonyOS/Day5 Assingment/trainingApp/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 00000000..f59159e8 --- /dev/null +++ b/HarmonyOS/Day5 Assingment/trainingApp/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://repo.huaweicloud.com/gradle/gradle-6.3-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/HarmonyOS/Day5 Assingment/trainingApp/gradlew b/HarmonyOS/Day5 Assingment/trainingApp/gradlew new file mode 100644 index 00000000..2fe81a7d --- /dev/null +++ b/HarmonyOS/Day5 Assingment/trainingApp/gradlew @@ -0,0 +1,183 @@ +#!/usr/bin/env sh + +# +# Copyright 2015 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin or MSYS, switch paths to Windows format before running java +if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=`expr $i + 1` + done + case $i in + 0) set -- ;; + 1) set -- "$args0" ;; + 2) set -- "$args0" "$args1" ;; + 3) set -- "$args0" "$args1" "$args2" ;; + 4) set -- "$args0" "$args1" "$args2" "$args3" ;; + 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=`save "$@"` + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +exec "$JAVACMD" "$@" diff --git a/HarmonyOS/Day5 Assingment/trainingApp/gradlew.bat b/HarmonyOS/Day5 Assingment/trainingApp/gradlew.bat new file mode 100644 index 00000000..62bd9b9c --- /dev/null +++ b/HarmonyOS/Day5 Assingment/trainingApp/gradlew.bat @@ -0,0 +1,103 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windows variants + +if not "%OS%" == "Windows_NT" goto win9xME_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/HarmonyOS/Day5 Assingment/trainingApp/settings.gradle b/HarmonyOS/Day5 Assingment/trainingApp/settings.gradle new file mode 100644 index 00000000..4773db73 --- /dev/null +++ b/HarmonyOS/Day5 Assingment/trainingApp/settings.gradle @@ -0,0 +1 @@ +include ':entry'